Info

此问题已关闭。 请重新打开它进行编辑或回答。

If statement not working?

1 次查看(过去 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