subplot(7,1,2);plot(t,imf(1,:));title('IMF1');

subplot(7,1,3);plot(t,imf(2,:));title('IMF2');

subplot(7,1,4);plot(t,imf(3,:));title('IMF3');

subplot(7,1,5);plot(t,imf(4,:));title('IMF4');

subplot(7,1,6);plot(t,imf(5,:));title('IMF5');

subplot(7,1,7);plot(t,imf(6,:));title('IMF6');

可以生成代码:

for i=1:6

subplot(7,1,i+1);

plot(t,imf(i,:));

eval_r(['title(''IMF',int2str(i),'');']);

end

例子二:

文件夹里有n个xlsx文件怎么循环语句调用呢?

for i=1:20

str =

['xlsread(''C:\Users\vlonlove\Desktop\新建文件夹\',num2str(i),'.xlsx'')'];

aa=eval_r(str);

%%%或者直接aa=xlsread(['C:\Users\vlonlove\Desktop\新建文件夹\',num2str(i),'.xlsx'])

end

这里的num2str功能是将数字转换为字符串形式(只有字符串才能在xlsread中引用)

引申一下:

怎么实现将数据a=[1,2,3,4,5]读入到xlsx的指定位置?

for i=1:4

A=‘A’+I;

xlswrite('C:\Users\Administrator\Desktop\新建文件夹\2.xlsx',aa(3),'sheet1',[char(A),'1'])

end

备注:[]括起来的是一个字符串。

clear;

clc;

for ii = 1:800

if ii<10

temp = strcat('00',num2str(ii));

A{1,ii} = strcat(temp,'right');

elseif ii<100

temp = strcat('0',num2str(ii));

A{1,ii} = strcat(temp,'right');

else

A{1,ii} = strcat(num2str(ii),'right');

end

end

for jj = 1:2 %%%%%% 假设有两个,在桌面myhelp的文件夹内

B = 'C:\Documents and Settings\Administrator\桌面\myhelp\';

cxd = strcat(B,A{1,jj})

xlsread(cxd)

end

输出结果:

cxd =

C:\Documents and Settings\Administrator\桌面\myhelp\001right

ans =

1

cxd =

C:\Documents and Settings\Administrator\桌面\myhelp\002right

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐