matlab里多个for循环的嵌套循环语句怎么写

clear
A = dir(fullfile('E:\2007\','*.dat'));
Leng=length(A);
B=zeros(1,Leng);
for i=1:Leng
SB=strcat('E:\2007\',A(i).name)
file_name{i} =SB;
temp=load (file_name{i});
hei=file_name{i}(:,3);
ph=file_name{i}(:,4);
nn=length(hei);
for i=2:nn
x=(hei(i)-hei(i-1))/(ph(i)-ph(i-1))
if(x<-157)
csvwrite('E:\2007\b.txt',x)
end
end
end
为什么我的代码只执行了第一个循环 只能输出文件名

不知道参数具体数值无法运行,这里给你指出编程错误。

1
2
3
4
5
6
7
8
9
10

if s1>s2
for i=150:15:0;%应修改为i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if abs(s10-s2)<0.01
subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
%这里你是否只需画一幅图?根据你的表达退出所有循环这里要加个break
end
end%最后仍缺个end

修改程序如下:

1
2
3
4
5
6
7
8
9
10
11

if s1>s2
for i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if abs(s10-s2)<0.01
subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
break
end
end
end
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-08-31
内嵌循环用break还不行最后做个判断吧flag=1;whileflagfori=1:10ifi>9flag=0%跳出while循环break;%跳出for循环endendend
第2个回答  2017-08-29
for i=0:10 iend
第3个回答  2020-06-05
不知道参数具体数值无法运行,这里给你指出编程错误。
1
2
3
4
5
6
7
8
9
10
if
s1>s2
for
i=150:15:0;%应修改为i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if
abs(s10-s2)<0.01
subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
%这里你是否只需画一幅图?根据你的表达退出所有循环这里要加个break
end
end%最后仍缺个end
修改程序如下:
1
2
3
4
5
6
7
8
9
10
11
if
s1>s2
for
i=150:-15:0
new1=AFFT(im1,i);
s10=AS(new1);
if
abs(s10-s2)<0.01
subplot(1,2,1),imshow(new1,[])
subplot(1,2,2),imshow(im2,[])
break
end
end
end