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.
Info
此问题已关闭。 请重新打开它进行编辑或回答。
If statement not working?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!