storing function outputs from a nested for loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
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);
Réponse acceptée
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
0 commentaires
Plus de réponses (0)
Voir également
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!