필터 지우기
필터 지우기

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

조회 수: 7 (최근 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에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by