Write a cell array which contains strings to a csv file
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 23 Mär. 2016
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 Kommentare
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!