- 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 次查看(过去 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
2019-10-29
"...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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Oceanography and Hydrology 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!