Export data to specified excel rows using writematrix
41 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Cassandra Martin
am 13 Feb. 2022
Beantwortet: Jeremy Hughes
am 14 Feb. 2022
Hi,
I am trying to export data to some rows in excel. Here is an example:
writematrix(subjects,'Matlab to Excel Subject Data.xlsx','Sheet',2,'Range','B3:I3')
I have tried using 'WriteMode' and 'append' however, this overrides my headings and titles in the excel file. I would like to fill B3:I3 and continute to B40:I40. I have tried using a for loop which will increase the row by 1.
Here is what I tried:
for i = 3:40
writematrix(subjects,'Matlab to Excel Subject Data.xlsx','Sheet',2,'Range','B',(i+1),':I'(i+1))
end
Unforetunely this does not work. Is there a solution to this?
10 Kommentare
Voss
am 13 Feb. 2022
Since randn(1,8) works, I guess the thing to do would be to make sure the variable subjects has the values you expect right before you write it to file. It looks like maybe the value of subjects is set by the script Master_File, so you might set a breakpoint in there where subjects is set, and/or a breakpoint on the writematrix() line so you can check the value of subjects right before it goes to file.
Akzeptierte Antwort
Jeremy Hughes
am 14 Feb. 2022
I believe it should be possible to do this using (almost) the syntax you tried, and there are some suggestions in the comments, but I wanted to share the "WriteMode" parameter as that should do exactly what you're looking for.
for i = 1:5
writematrix(randn(1,3),'test.xlsx','WriteMode','append');
end
A = readmatrix('test.xlsx')
That said, it's going to be a lot slower writing single rows at a time, since writematrix has to open, write, and close the file each time. It's not meant for incremental writing. So the solution to build up the matrix first makes the most sense to me.
The append appoach could be useful if you have very large arrays, but I suspect that the XLSX format will limit you before the array size will.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets 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!