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

8 ビュー (過去 30 日間)
Guangxi
Guangxi 2015 年 1 月 9 日
回答済み: Angga Lisdiyanto 2016 年 5 月 11 日
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 Center および File ExchangeSpreadsheets についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by