Write a cell array which contains strings to a csv file
1 次查看(过去 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!