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

6 次查看(过去 30 天)
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!

回答(2 个)

Stalin Samuel
Stalin Samuel 2015-1-9
编辑:Stalin Samuel 2015-1-9
  1 个评论
Guangxi
Guangxi 2015-1-9
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.

请先登录,再进行评论。


Angga Lisdiyanto
Angga Lisdiyanto 2016-5-11

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by