storing function outputs from a nested for loop

1 vue (au cours des 30 derniers jours)
Mos_bad
Mos_bad le 4 Sep 2019
Commenté : Stephen23 le 6 Sep 2019
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 commentaires
Stephen23
Stephen23 le 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);

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by