xlsWrite overwrites data despite setting a specific range
Show older comments
I am trying to extrac data from Matlab into excell. I have a structure that contains several matrixes (these range from the size 1x600 to 1x800). I isolated each matrix in matlab (and called them m1, m2, m3...). But when I try to export them with xlswrite it seems to copy each matrix on top of the previous one, so instead of having an excell file with all of my matrixes, each one in a separate line, I have one single line showing the last matrix (m4 in this case).
I tried using '1:1', '2:2', etc, to write them in separate fields, but I still get the same error. Any suggestions? I have tried setting the range as 'A1:ZZ1', 'A2:ZZ2', but that didn't work either.
m1 = Structure(1).matrix; % Extracts the value of matrix of the of the first data point in structure
m2 = Structure(2).matrix; %
m3 = Structure(3).matrix;
m4 = Structure(4).matrix;
filename = 'Filename.csv';
xlswrite(filename,m1,'1:1');
xlswrite(filename,m2,'2:2');
xlswrite(filename,m3,'3:3');
xlswrite(filename,m4,'4:4');
2 Comments
filename = 'Filename.csv';
xlswrite(filename,m1,'1:1');
xlswrite(filename,m2,'2:2');
xlswrite(filename,m3,'3:3');
xlswrite(filename,m4,'4:4');
You're not writing an Excel file but a csv text file -- for which the 'Range' argument is ineffective as you've discovered because it is a sequential file.
Walter Roberson
on 3 Feb 2020
Also xlswrite will overwrite everything on Mac and Linux and on Windows that does not have Excel.
Accepted Answer
More Answers (0)
Categories
Find more on Text Files 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!