Write a cell array which contains strings to a csv file
4 ビュー (過去 30 日間)
古いコメントを表示
I am trying to write a single precision floating point array to a csv file.
csvwrite('abc.csv',num2hex(single(magic(4))))
After each character, comma appears.
How to write a 4x4 matrix to csv file in which all elements are a single string.
The contents of the csv file looks like this:
4,1,8,0,0,0,0,0
4,0,a,0,0,0,0,0
4,1,1,0,0,0,0,0
4,0,8,0,0,0,0,0
4,0,0,0,0,0,0,0
4,1,3,0,0,0,0,0
4,0,e,0,0,0,0,0
4,1,6,0,0,0,0,0
4,0,4,0,0,0,0,0
4,1,2,0,0,0,0,0
4,0,c,0,0,0,0,0
4,1,7,0,0,0,0,0
4,1,5,0,0,0,0,0
4,1,0,0,0,0,0,0
4,1,4,0,0,0,0,0
3,f,8,0,0,0,0,0
I don't want any commas in between the string.
0 件のコメント
回答 (1 件)
Walter Roberson
2016 年 3 月 23 日
You cannot use csvwrite() for this. You will need to either use xlswrite() or write the file yourself.
fid = fopen('abc.csv', 'wt');
fmt = [repmat('%s,', 1, 3), '%s\n'];
datacell = arrayfun(@(x) num2hex(x), single(magic(4)), 'Uniform', 0);
fprintf(fid, fmt, datacell .'); %transpose is needed
fclose(fid)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!