Write a cell array which contains strings to a csv file

4 ビュー (過去 30 日間)
Vinod
Vinod 2016 年 3 月 23 日
回答済み: Walter Roberson 2016 年 3 月 23 日
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.

回答 (1 件)

Walter Roberson
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)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by