How can I use xlswrite to get data from GUI after I push a button?
1 view (last 30 days)
Show older comments
Alexandra Topciov
on 7 Sep 2015
Commented: Alexandra Topciov
on 14 Sep 2015
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 Comments
Accepted Answer
Geoff Hayes
on 7 Sep 2015
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!
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!