- Get rid of the assignin calls.
- Define all function outputs that you need.
- Call the function with those outputs.
- Use indexing to allocate the outputs to arrays.
Running a function multiple times and storing outputs for each of the runs
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have this following function where I need to run this multiple times (over 1000 times) which gives 1000 different outputs since parameter values are being changed for each run. Here, I like to know if there is a way to record ech of the 1000 outputs (NSE and NSE_monthly are generated after each run so I'm simplying grabbing them).
If you need more details or explainations, please let me know.
Much appreciated.
function [SimRR,NSE] = hydroModel(x)
WriteInput_Works(x); %another function within a function (this function contols the parameters)
%water quality
SimRR = dlmread('0000610.txt','\t','I222..I1037');
NSE_num=importdata('subass2.txt','\t');
NSE=NSE_num.data([2]);
SimTP_m=importdata('mapCCTP.txt',',');
SimTP_m=SimTP_m.data(1,2:end);
SimTP_m=simTP_m';
%obs monthly TP
ObsTP_m=[86.8519 73.6446 187.3597 219.0595 71.9128 187.5019 102.1246 62.5333 57.954 182.2784 91.3264 178.9219 139.8846 216.9958 260.1931 303.2601 59.3539 56.768 50.7397 181.0545 68.3858 51.7204 47.488 210.4897 279.6822 159.7489 226.821 237.4075 252.5613 67.3639 46.4805 41.0104 39.584 39.2436 241.1982 94.3966];
NSE_monthly=NSE(obsTP_m,SimTP_m); %NSE function
assignin('base','NSE_m',NSE_monthly);
assignin('base','NSE',NSE);
end
2 comentarios
Stephen23
el 29 de Oct. de 2019
"...a way to record ech of the 1000 outputs"
Note that there is little point in importing the same files thousands of times: just import them once, and pass their data as input arguments.
Respuestas (0)
Ver también
Categorías
Más información sobre Oceanography and Hydrology 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!