Azzera filtri
Azzera filtri

How can I add a new row of results in excel every time when I click the push button in GUI?

7 visualizzazioni (ultimi 30 giorni)
I am new to Matlab, been trying to write a program to simulate fluid dynamics, the codes seem working fine, however I am struggling with how to export the results to excel. To make it easier to understand, here is a simple example of what I want to do. Assuming I have 2 input variables (a and b) and 3 output variables (c,d and e), where c=a+b, d=a*b, e=a/b. I can type in any number I want in boxes a and b, then press the push button, the program will tell me the values of c, d and e. Below are the m file:
function pushbutton1_Callback(hObject, eventdata, handles)
c=str2num(get(handles.a,'string'))+str2num(get(handles.b,'string'))
set(handles.c,'string',c)
d=str2num(get(handles.a,'string'))*str2num(get(handles.b,'string'))
set(handles.d,'string',d)
e=str2num(get(handles.a,'string'))/str2num(get(handles.b,'string'))
set(handles.e,'string',e)
m=[str2num(get(handles.a,'string')) str2num(get(handles.b,'string')) c d e]
filename= 'testdata.xlsx';
xlswrite(filename,m)
However, it seems Matlab simply overwrites the old spreadsheet every time when I press the push button, what I really want for Matlab is to add another row of data below the existing one every time when I press the button. Can anyone help me with that? Thanks in advance!

Risposte (2)

Stalin Samuel
Stalin Samuel il 9 Gen 2015
Modificato: Stalin Samuel il 9 Gen 2015
  1 Commento
Guangxi
Guangxi il 9 Gen 2015
Thanks, just read the links you sent me, however those examples are not exactly the same one as what I have. In most of their cases, a and b were set in a certain range. However in my case, a and b can be any random number, I can type whatever numbers I want in boxes a and b, then press the button to see what are the corresponding values of c, d and e. So it is hard to say how many rows I will have eventually in the spreadsheet, it really depends on how many times I will press the button.

Accedi per commentare.


Angga Lisdiyanto
Angga Lisdiyanto il 11 Mag 2016

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by