storing function outputs from a nested for loop

1 visualización (últimos 30 días)
Mos_bad
Mos_bad el 4 de Sept. de 2019
Comentada: Stephen23 el 6 de Sept. de 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 comentarios
Stephen23
Stephen23 el 6 de Sept. de 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);

Iniciar sesión para comentar.

Respuesta aceptada

KSSV
KSSV el 4 de Sept. de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by