Convert Matrix into string
5 views (last 30 days)
Show older comments
Dear all,
Lets assume I have matrix
A = [1 2 3 4 5;6 7 8 9 10;11 12 13 14 15];
Now I want to write CSV file in following format
1, 2 3 4 5
6, 7 8 9 10
11, 12 13 14 15
first element should be the first column and all remaining the other column separated by space.
0 Comments
Answers (1)
Walter Roberson
on 9 Jun 2018
fopen / fprintf / fclose
2 Comments
Walter Roberson
on 9 Jun 2018
I didn't say anything about using mat2str.
fmt = ['%d, ', repmat('%d ', 1, size(A,2)-2), '%d\n'];
fid = fopen('YourOutputFile.csv', 'wt');
fprintf(fid, fmt, A.'); %transpose is important
fclose(fid)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!