Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
If statement not working?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Geoff Hayes
le 3 Août 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.
Réponses (0)
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!