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 CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by