Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

If statement not working?

조회 수: 6 (최근 30일)
tash7827
tash7827 2015년 8월 3일
마감: Walter Roberson 2015년 8월 3일
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
Geoff Hayes
Geoff Hayes 2015년 8월 3일
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.

답변 (0개)

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by