storing function outputs from a nested for loop
1 次查看(过去 30 天)
显示 更早的评论
I want to store function output through nested for loop. Here is the code:
maxDisp_x=cell(Nrt,lhsN,Nsnro);
for scenario=1:Nsnro
for i=1:Nrt
.......
for j=1:lhsN
.........
for k = 1 : NGM
[maxDisp_x]=Res_TH_PstProcs(scenario,i,j,k);
maxDisp_x=maxDisp_x{Nrt,lhsN,Nsnro};
end
end
end
end
Here is the Res_TH_PstProcs function:
function [maxDisp_x] = Res_TH_PstProcs(scenario,i,j,k)
tmp1_ = eval(['importdata(''./Output/TimeDepTHOutput/Scenario',num2str(scenario),'/Time',num2str(i),'/Run',num2str(j),'/GM',num2str(k),'/upDispXYZ','.out'')']);
dispSupStr_x = mpDisp(:,1);
maxDisp_x=max(abs(dispSupStr_x));
end
2 个评论
Stephen23
2019-9-6
Note eval is not required and not recommended for trivially calling functions like that.
fmt = './Output/TimeDepTHOutput/Scenario%d/Time%d/Run%d/GM%d/upDispXYZ.out';
fnm = sprintf(fmt,scenario,i,j,k);
tmp1_ = importdata(fnm);
采纳的回答
KSSV
2019-9-4
maxDisp_x=cell(Nrt,lhsN,NGM);
for scenario=1:Nsnro
for i=1:Nrt
.......
for j=1:lhsN
.........
for k = 1 : NGM
maxDisp_x{i,j,k}=Res_TH_PstProcs(scenario,i,j,k);
end
end
end
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!