MATLAB Answers

how can i write data into excel sheet in MATLAB ?

2 views (last 30 days)
I have a GUI, from which I need to write data to an excel sheet. The data contains both text and numeric content, which is read from a sheet, but before I write to same sheet. it is edited, the data for a specific row/ column and then write whole data to the same sheet For example, I made changes to one or more cells in specific row /column keeping others unchanged ... then it needs to write the whole data after the changes to same sheet using pushbutton callback

  2 Comments

Walter Roberson
Walter Roberson on 7 Jul 2018
xlswrite() and writetable() both accept sheet numbers or names.
Vasishta Bhargava
Vasishta Bhargava on 7 Jul 2018
I use xlsread() function to read data from file as shown below
[dataP dataN Raw] = xlsread(LL,All{1});
Then I make changes to dataP which is numeric array, and later when I write to excel sheet using following code
xlswrite(LL,Raw(3:end,:),All{1},'A3:BE42');
It does not update the data, means edited data in dataP array is not reflected ... though it writes both numeric and text arrays to location specified. why ?

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 7 Jul 2018
"It does not update the data, means edited data in dataP array is not reflected" Well, did you write out dataP? No. You wrote out Raw only. So you did not write out anything that got changed, so of course nothing got changed. Write out dataP if you want a new dataP in the workbook file.
By the way, don't use All for a variable name - it's too close to a built-in function called all().

  3 Comments

Vasishta Bhargava
Vasishta Bhargava on 7 Jul 2018
If I write out dataP only, it is erasing the text data in existing file, though it updates with the values changed. and if write both dataP and dataN one after another, dataN is erasing the numeric data so, how can I ensure that both text and numeric arrays are present after making changes ?
Image Analyst
Image Analyst on 7 Jul 2018
You can make up a cell array and write that out with one call to xlswrite.

Sign in to comment.

More Answers (0)


Translated by