I have a function,
function cubefinal = sensingmatrix3d(time)
and I call it like this if I want time=3:
cubefinal = sensingmatrix3d(3);
but it is not working (the body of the function is correct) because when I displayed 'time', answers seemed totally random:
>> test3dmatrixtime = 6>> test3dmatrixtime = 6>> test3dmatrixtime = 7>> test3dmatrixtime = 7>> test3dmatrixtime = 4>> test3dmatrixtime = 5
could somebody please tell me why time is random? and how to fix it? thank you.
Edit: sorry — here is my code
function cubefinal = sensingmatrix3d(time)exposure=zeros(60,96,10);if time==3 for j=1:size(exposure,1); for jj=1:size(exposure,2); randnum=randi([1 8]); exposure(j,jj,randnum:randnum+2)=1; %if rand < 0.003
% checkRow=reshape(exposure(j,jj,:), [1 10])
%end
end endelseif time == 4 for j=1:size(exposure,1); for jj=1:size(exposure,2); randnum=randi([1 7]); exposure(j,jj,randnum:randnum+3)=1; end endelseif time == 5 for j=1: size(exposure,1); for jj=1:size(exposure,2); randnum=randi([1 6]); exposure(j,jj,randnum:randnum+4)=1; end endelseif time == 6 for j=1:size(exposure,1); for jj=1:size(exposure,2); randnum=randi([1 5]); exposure(j,jj,randnum:randnum+5)=1; end endelseif time == 7 for j=1:size(exposure,1); for jj=1:size(exposure,2); randnum=randi([1 4]); exposure(j,jj,randnum:randnum+6)=1; end endend cubefinal=exposure;disp(time)end
Best Answer