storing function outputs from a nested for loop

1 view (last 30 days)
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 Comments
Stephen23
Stephen23 on 6 Sep 2019
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);

Sign in to comment.

Accepted Answer

KSSV
KSSV on 4 Sep 2019
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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!