从脚本(matlab)创build输出matrix

我有一个脚本,如下所示:

for (do something) end 

还有使用从循环输出的数据的输出(每当脚本运行时都会改变):

 A = 1 A = 1.5 

等等。

我正在寻找把这个输出每次都改变成一个matrix。 这可行吗?

 for number of iterations (Call script) end Output to excel 

我想将数据存储到matrix中的原因是能够一次性将所有答案(多次迭代)输出到Excel中。

编辑:为了让我的输出看起来像这样的更好的图片

 Output = [rand() rand() rand(); rand() rand() rand()]; 

那么我使用这个来创build一个新的variables:

 var = Output(1,1)./Output(2,1); 

每次运行脚本时,答案都会改变。 这个新的答案每次,我正在寻找保存在一个matrix。 希望这能说明问题。

假设var是每次迭代后要放在matrix中的东西,我build议如下:在代码中添加另一个for循环,例如循环遍历i,然后最后不要赋值给var,而是VAR(i)中。

根据你的输出,你需要selectvariablestypes的variables,例如单元格或matrix。

根据每个循环的输出/输出types,可以简单地将中间结果保存在许多MATLAB数据结构中的一个中(randn在下面用作“做某事”的示例):

 nIterations = 10; % scalar output A = zeros(1, nIterations); for n=1:nIterations A(n) = randn; end % matrix ouput of possibly changing size B = cell(1, nIterations); for n=1:nIterations B{n} = randn(1, n+1); end % matrix output of fixed size C = zeros(3, 3, nIterations); for n=1:nIterations C(:,:,n) = randn(3, 3); end