简体   繁体   English

将向量保存到矩阵Matlab中

[英]Saving vectors into a matrix matlab

I have a bunch of arrays that I have generated from a loop 我有一堆从循环中生成的数组

Peaks [1, 2, 3, 4, 5]
Latency [23,24,25,26,27] etc.

I want to put all of those in a matrix that will look like that: 我想将所有这些放到看起来像这样的矩阵中:

Peaks Latency
1      23
2      24
3      25
4      26
5      27

Then I'll want to save this as a text file. 然后,我将其另存为文本文件。

It seems like it would be fairly simple but can't seem to find anything that closely speaks to me right now. 似乎这很简单,但现在似乎找不到与我密切相关的任何内容。

Concatentate: Concatentate:

>> Peaks = [1 2 3 4 5];
>> Latency = [23 24 25 26 27];
>> T = [Peaks(:) Latency(:)]
T =
     1    23
     2    24
     3    25
     4    26
     5    27

Write: 写:

fileName = 'PeaksLatency.txt';
hdr = {'Peaks','Latency'}
txt = sprintf('%s\t',hdr{:}); txt(end) = [];
dlmwrite(fileName,txt,'');                         % write header
dlmwrite(fileName,T,'-append','delimiter','\t');   % append data

Here is the code 这是代码

Peaks = [1, 2, 3, 4, 5].';
Latency = [23,24,25,26,27].';

T = table(Peaks, Latency);

writetable(T,'table.txt', 'Delimiter', '\t');

Note that you need to make Peaks and Latency into column vectors (use .' operator). 请注意,您需要将PeaksLatency为列向量(使用.'运算符)。

Ref: http://www.mathworks.com/help/matlab/ref/writetable.html 参考: http : //www.mathworks.com/help/matlab/ref/writetable.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM