Run a script file "i" times and save output variable to a 3D array
4 views (last 30 days)
I have a script file "myscript.m" where each time the script file is executed I obtain a 1001x2 output variable "output".
I would like to execute this script "i" times in a loop, and save the output variable as an array (output,i) = (1001,2,i)
I've tried the following code in a new script file and am able to obtain a (1001,2,i) array, however, only the first column of my array is populated with the correct values from "output", the second column is zeros, which should not be the case.
result = zeros(1001,2,5); %preallocate array
for i = 1:5
run('myscript'); % where "output" = 1001x2, is computed
I know I've missed something trivial here.
Gargi Patil on 16 Apr 2021
The code provided by you should correctly assign the values to result. You can also simplify it by using the following code in the for loop:
The undesired assignment could be occurring due to incorrect assignment of values to output. Ensure that run() is computing output correctly.