What is the alternate to eval function in a forloop?

6 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Xingwang Yong
Xingwang Yong il 22 Apr 2021
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

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by