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

问题描述 投票:0回答:1

为了分析某些数据,我有几个脚本,它们使用相同的输入并计算不同的内容。我想让Matlab然后将每个脚本的输出写入相同的csv,以便将所有输出都放在一个位置。我该怎么做呢?甚至没有可能在Matlab中制作一个巨大的矩阵并将整个矩阵写成一个逗号吗?据我所知,writematrix仅写入第一列。

示例:

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

writematrix(A,'M.xls')%写入csv的第1列

writematrix(B,'M.xls')%这将覆盖先前的命令

您可以在xcel中写到不同的图纸,但这不合适。

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

TIA

matlab csv overwrite
1个回答
0
投票

使用'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');
© www.soinside.com 2019 - 2024. All rights reserved.