What is the alternate to eval function in a forloop?
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!