[英]Saving vectors into a matrix matlab
我有一堆從循環中生成的數組
Peaks [1, 2, 3, 4, 5]
Latency [23,24,25,26,27] etc.
我想將所有這些放到看起來像這樣的矩陣中:
Peaks Latency
1 23
2 24
3 25
4 26
5 27
然后,我將其另存為文本文件。
似乎這很簡單,但現在似乎找不到與我密切相關的任何內容。
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
寫:
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
這是代碼
Peaks = [1, 2, 3, 4, 5].';
Latency = [23,24,25,26,27].';
T = table(Peaks, Latency);
writetable(T,'table.txt', 'Delimiter', '\t');
請注意,您需要將Peaks
和Latency
為列向量(使用.'
運算符)。
參考: http : //www.mathworks.com/help/matlab/ref/writetable.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.