Unequivalent loop structure in MATLab -
i have 2 versions of code - wrote second (more explicit) loop when first didn't wanted.
where did go wrong? suspect slicing problem (as in, i'm not correctly slicing data out)
the first version, doesn't want, commented out above loop:
rbool = false(h.numdirs, h.numtimes, h.numr); d = 1:h.numdirs u_first = h.data(d,1,:); u_first = u_first{1}; t = 2:h.numtimes u = h.data(d,t,:); u = u{1}; du = abs(u-u_first); %rbool(d,t,:) = (du > (smallval*u_first) | rbool(d,t-1)); r=1:h.numr rbool(d,t,r) = (du(r) > (smallval*u_first(r))| rbool(d,t-1,r)); end end end
you missing third index of second rbool
in commented line:
rbool(d,t,:) = (du > (smallval*u_first) | rbool(d,t-1,:));
although i'd parenthesize this:
rbool(d,t,:) = (du > (smallval*u_first)) | rbool(d,t-1,:);
the version had implicitly assumed r==1
, think.
and can simplify code setting
u = h.data{d,t,1};
instead of cutting out cell vector , choosing first element.
Comments
Post a Comment