How can I use xlswrite to get data from GUI after I push a button?
조회 수: 1 (최근 30일)
이전 댓글 표시
I need to get some data from GUI and write it in an excel-file but only after i click a button, and I don't want to overwrite the data after each button press but make it go to the next line. Can anyone help me?
댓글 수: 0
채택된 답변
Geoff Hayes
2015년 9월 7일
Alexandra - if you don't want to overwrite the data that has been previously written to the Excel spreadsheet, then just specify the location (row) of where you want to write the data to. For example,
function pushbutton1_Callback(hObject, eventdata, handles)
% get data from GUI (assume row)
rowData = [1 2 3 4 5];
% get row to write to
row = 1;
if isfield(handles,'row')
row = handles.row;
end
% write the data to file to row Ax
xlswrite('myExcelFile.xls', rowData, ['A' num2str(row)]);
% update handles struct with the new row
handles.row = row + 1;
guidata(handles);
Note how we use the range parameter of xlswrite to determine which row we write the new data to: we write the data starting in the first column (A) and concatenate with that the integer row. We save to the handles structure the new row to use when we want to write data to this file upon the next press of the button (using guidata).
The isfield check is there to ensure we don't try to access a field of handles that doesn't exist.
Try the above and see what happens!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!