How can I use xlswrite to get data from GUI after I push a button?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Alexandra Topciov
el 7 de Sept. de 2015
Comentada: Alexandra Topciov
el 14 de Sept. de 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 comentarios
Respuesta aceptada
Geoff Hayes
el 7 de Sept. de 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!
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!