Filter löschen
Filter löschen

How to use XLSWRITE function in the for loop?

3 Ansichten (letzte 30 Tage)
N/A
N/A am 6 Feb. 2019
Beantwortet: Shawn Duenas am 6 Feb. 2019
I have a code (attached file) which requires inputing any number detected in the matlab code into rows and columns within the same dimensions provided in the MATLAB code. I know the syntax is
xlswrite(filename, M)
But how do I make it write in different rows and columns on the excel file. Attached is the code for further clarification. I need help determining where exactly I'm to place this line of code so that the code runs perfectly. And the new inputted value doesn't overlap the previous one.
Attached are all the required codes,images and source files.
Thank you
  5 Kommentare
Rik
Rik am 6 Feb. 2019
Comment put in a flag by Taofeek Obafemi-Babatunde:
Yes file name is the same
Walter Roberson
Walter Roberson am 6 Feb. 2019
When you are looping writing to different locations in the same excel file, then a lot of the time the best approach is Don't Do That. That is, most of the time it is more efficient to read in the entire file, change the locations in memory, and then write out the entire new version once at the end. This is especially true for .xlsx files, which are really a zip'd directory of text XLM files that have to be updated as text each time you make a change.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Shawn Duenas
Shawn Duenas am 6 Feb. 2019
Keep a counter of the number of rows:
insertRow=1;
for iMat=1:nMat
nRow=size(M,1);
xlsRange=['A',int2str(insertRow),':Z',int2str(insertRow+nRow-1)]
xlswrite(filename, M, xlsRange);
insertRow=insertRow+nRow;
end
Note that if the width of M is 26 then printing from A:Z works, but you'll need to find an algorithm that gives you the right column letter for your matrix width (size(M,2)).

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by