How to export matrix in the form of (column number, row number, value) in CSV?
2 ビュー (過去 30 日間)
古いコメントを表示
I have a 100x100 matrix, and I want to export it to CSV in the form of (column number, row number, value). For example,
Matrix A:
[1] [2] [3] ... [100]
[1] 0.69 0.02 0.81 ... 0.55
[2] 0.23 0.67 0.02 ... 0.21
[3] 0.06 0.22 0.67 ... 0.96
[...] ... ... ... ... ...
[100] 0.01 0.05 0.22 ... 0.88
The expected CSV output is
Column Row Value
1 1 0.69
1 2 0.23
1 3 0.06
...
1 100 0.01
2 1 0.02
2 2 0.67
...
100 100 0.88
How can I do this in matlab? Your help is greatly appreciated.
0 件のコメント
採用された回答
Voss
2022 年 1 月 18 日
A = randn(8,4)
[m,n] = size(A);
[c,r] = meshgrid(1:n,1:m);
writematrix([c(:) r(:) A(:)],'output.csv');
% check the result
readmatrix('output.csv')
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!