Running a function multiple times and storing outputs for each of the runs

1 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2019-10-29
"...a way to record ech of the 1000 outputs"
  1. Get rid of the assignin calls.
  2. Define all function outputs that you need.
  3. Call the function with those outputs.
  4. Use indexing to allocate the outputs to arrays.
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.
Jung
Jung 2019-10-30
Each run provides only one NSE for that run that's why I need to import the same files many times.
Is there a way to store these NSE values within a function (maybe an array) and call it out once at the end?
The structure of this hydrological model script is a bit unusual to me and thus I try my best not to touch the initial workspace.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Oceanography and Hydrology 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by