Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Why does my for-loop nested in an if-statement not work?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have an for-loop inside an if-statement nested again in another for-loop (I know sounds complicated, example below), which seems to run perfeclty, as long as until the loop is called the SECOND time. Then it gives me the error:
Index exceeds matrix dimensions.
Error in code (line 50)
imb=squeeze(B_proc(n,:,:));
Does anybody have an idea why?
Here the simplified for-if-for-loop:
k=1; for i=2:length(proc_core) proc=cell2mat(proc_core(i,2)); sz=size(proc); l=sz(1); vs=cell2mat(proc_core(i,3)); if sz(2)==512 && sz(3)==512 && vs==2.5 kl=k+l-1; Core_proc(k:kl,:,:)=proc; k=k+l; elseif vs==2.5 for n=1:length(proc) imb=squeeze(proc(n,:,:)); imb=imresize(imb,[512 512]); Core(k,:,:)=imb; k=k+1; end end end
1 Kommentar
Walter Roberson
am 20 Jul. 2016
duplicated by later more complete http://www.mathworks.com/matlabcentral/answers/296421-why-does-my-for-loop-nested-in-an-if-statement-not-work
Antworten (0)
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!