What is the alternate to eval function in a forloop?

6 ビュー (過去 30 日間)
Wiqas Ahmad
Wiqas Ahmad 2021 年 4 月 22 日
回答済み: Xingwang Yong 2021 年 4 月 22 日
EC = [0.0052 0.0104 0.0156 0.0234];
Reff =[4 8 12 16 20]
for i=1:length(FOV)
f(i)=figure(i);
hold on
for j = 1:length(EC)
for k = 1:length(Reff)
filename1 = ['FOV_',num2str(FOV(i)),'mrad\',num2str(EC(j)),'\',num2str(Reff(k)),'um\out_resultsG_I0.dat'];
eval(['I',num2str(i),num2str(j),num2str(k),'=','getsiganl(filename1)',';']);
eval(['II',num2str(i),num2str(j),num2str(k),'=','smooth(sum(I',num2str(i),num2str(j),num2str(k),',2)',');']);
I have two folders in the directory in which I have the same data files.I am accessing the data at once. The path of the file is \FOV_1mrad\0.0052\4um\out_resultsG_I0 and \FOV_2mrad\0.0052\4um\out_resultsG_I0. The data file I have accessed by filename1=[......]. In the eval function,I is the variable inside the data file (out_resultsG_I0.dat) and getsignal is the file name in the directory. I'd like to avoid using eval function and to use the load function instead to acess the file and load the variable but I'm unable to do so for three loop indices. I need some help to write these three expressions in load function form applying the three loop indices.

回答 (1 件)

Xingwang Yong
Xingwang Yong 2021 年 4 月 22 日
Using cell array should help
for i
for j
for k
I{i,j,k}=getsiganl(filename1);
II{i,j,k}=smooth(sum(I{i,j,k},2));
end
end
end

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by