Menu

#10 MatContM problem with subsasgn + suggested fix

v1.0_(example)
open
nobody
None
5
2017-10-11
2017-10-11
No

In some cases sub assignments in the model definition dydt can give errors in MatContM (command line mode). I found out that it has to do with the class ADTAYL.
Attached is an adapted Rfish.m file that generates the problem.

Main difference is the way dydt is defined:
%with subsasgn (easier vertorization and other advantages in my code)
function dydt = fun_eval(t,kmrgd,F,P,m1,m2,Beta)
dydt(1,:)=F.exp(-Beta.kmrgd(2,:)).kmrgd(2,:)+(1-m1).exp(-Beta.kmrgd(2,:)).kmrgd(1,:);
dydt(2,:)=P.exp(-Beta.kmrgd(2,:)).kmrgd(1,:)+(1-m2).kmrgd(2,:);

%original
function dydt = fun_eval(t,kmrgd,F,P,m1,m2,Beta)
dydt=[F.exp(-Beta.kmrgd(2)).kmrgd(2)+(1-m1).exp(-Beta.kmrgd(2)).kmrgd(1);
P.exp(-Beta.kmrgd(2)).kmrgd(1)+(1-m2).kmrgd(2)]
;

The problem is that I apply subsasgn to an empty variable. Therefore the fix seems easy, see bold text below and attached file.

function a = subsasgn(a,s,b)
% Subscripted reference for ADTAYL objects.
% The only ones allowed are of form A(I) and A(I,J).
%
% This should allow ':' as a subscript but doesn't, yet.
switch s.type
case '()'
if ~isa(b,'adtayl')
error('Incompatible left & right sides for assignment')
else
** if isempty(a)
%if a doesn't exist we first copy b
%else the result is not an ADTAYL object
a=b;
end**
% Pass indices to TC field, with : appended.
a.tc(s.subs{:},:) = b.tc;
end
otherwise
error('Wrong kind of subscripting for ADTAYL object')
end

2 Attachments

Discussion


Log in to post a comment.

MongoDB Logo MongoDB