Info

This question is closed. Reopen it to edit or answer.

If statement not working?

2 views (last 30 days)
tash7827
tash7827 on 3 Aug 2015
Closed: Walter Roberson on 3 Aug 2015
this is my code - it is supposed to be a binary array, where the length of time (through the array) that the "1"s are held is determined by "time" - why is the if statement not working based off of the output of "time"? all i get is a 60X96X10 array of zeros.
function cubefinal = sensingmatrix3d(~)
exposure=zeros(60,96,10);
time=randi([3 7]);
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;
end
end
elseif 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
end
elseif 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
end
elseif 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
end
elseif 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
end
cubefinal=exposure;
end
  1 Comment
Geoff Hayes
Geoff Hayes on 3 Aug 2015
Rather than posting a duplicate question, please just further the conversation at http://www.mathworks.com/matlabcentral/answers/232187-why-is-the-if-statement-not-working. Two answers have already been provided so it is there that you should either provide more details or ask for more help.

Answers (0)

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!