在多个脚本中使用 Matlab writematrix 写入同一个 csv

Using Matlab writematrix in several scripts to write to the same csv

为了分析一些数据,我有几个脚本接受相同的输入并计算不同的东西。我想让 matlab 然后将每个脚本的输出写入同一个 csv,这样我就可以将所有输出放在一个地方。我该怎么做呢?这甚至有可能 w/o 在 Matlab 中制作一个巨大的矩阵并将整个矩阵写在一个 comaand 中吗?据我所知,writematrix 只会写入第一列。

示例:

A = rand(1,10)'; B = rand(1,10)';

writematrix(A,'M.xls') %write to column 1 of csv

writematrix(B,'M.xls') %this overwrites the previous command

您可以在 xcel 中写入不同的工作表,但这不合适。

writematrix 的文档在这里:https://uk.mathworks.com/help/matlab/ref/writematrix.html

TIA

使用 'Range' 属性 指定第二列的范围(或起始单元格)并使用 'append' 作为 WriteMode,如下所示:

A = rand(10,1);    B = rand(10,1);  
%Side-note: ' is complex conjugate transpose. 
%Use transpose .' when you want to take transpose
%In this case, you can initialise the random matrices with 10x1 size 
%instead of 1x10 size and then taking the tranpose

writematrix(A,'M.xls');
%Assuming that B1 is the starting cell for the second column:
writematrix(B,'M.xls','Range','B1', 'WriteMode', 'append');