GUIDE GUI export data to Excel

조회 수: 4 (최근 30일)
Craig Saunders
Craig Saunders 2018년 8월 17일
편집: Adam Danz 2018년 8월 17일
Hello,
I've created a GUI in GUIDE and on the push of a button, I want to transfer data saved within the MATLAB 'base' workspace to an Excel file. I'm aware I can do this from the command window using the following code:
xlswrite('Vehicle_Data_', velocity_data, 'Sheet 1', 'A1')
However, how do I implement this within my pushbutton callback shown below:
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Ideally, an example would be a massive help!
Thanks,
Craig
  댓글 수: 1
Stephen23
Stephen23 2018년 8월 17일
편집: Stephen23 2018년 8월 17일
"I want to transfer data saved within the MATLAB 'base' workspace to an Excel file"
Magically grabbing data from another workspace and magically accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code which is hard to debug. The best solution is to pass that data properly as input/output arguments, exactly as the MATLAB documentation recommends:

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2018년 8월 17일
From your bushbutton callback you can evaluate the expression from the base workspace. If you get stuck, follow-up and I can help.
  댓글 수: 6
Adam Danz
Adam Danz 2018년 8월 17일
편집: Adam Danz 2018년 8월 17일
You could do it the same way you did with the velocity_data. You could do that in a loop and write each variable to a new sheet... something like this
Not tested
exportVars = {'velocity_data', 'force_data', 'distance_data'};
for i = 1:length(exportvars)
evalString = sprintf('''xlswrite(''Vehicle_Data'', %s, %s, ''A1''', exportVars{i}, sprintf('''Sheet %d''', i))
myVar = evalin('base', evalString);
end
Craig Saunders
Craig Saunders 2018년 8월 17일
Excellent, just what I needed - thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by