Adding a Callback to a Button to import data onto a plot

With the new version of MATLAB GUI, the structure has changed. I have added a callback to a button
% Button pushed function: Button
function ButtonPushed(app, event)
I cannot change the above^.
I have used the uigetfile function to import data.
[filename, pathname] = uigetfile('*.*');
plot('U',app.UIAxes);
Now I'm wondering how to import it onto app.UIAxes, can anyone help with this? I'm assuming my second line of code is wrong.
Thank you

 채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 31일
편집: Cris LaPierre 2021년 3월 31일

0 개 추천

You import it to the workspace, not the axis. Once you've created variables with your data, say X and Y, then plotting is as simple as plot(app.UIAxes,X,Y).
Your plot syntax is incorrect. Consult the documentation. The axis target is the first input. Also, what is 'U'? You can't plot a character.
If your code is working correctly in MATLAB, the only change you should need to make is to specify the target axes in your plot command. Can you successfully import a file and plot it in MATLAB?

댓글 수: 4

Thanks that's super helpful. U is a variable like X,Y. Is there information on how to import files using the uigetfile function for the GUI.
uigetfile is a just a graphic interface for selecting a file. It has not import capabilities. You would need to use the information returned by uigetfile to construct a method for loading/importing the selected file. You may find the fullfile function useful for this.
See this page for functions to consider for loading the file (organized by file type).
Cris LaPierre
Cris LaPierre 2021년 3월 31일
편집: Cris LaPierre 2021년 4월 1일
Consider going through MATLAB Onramp to learn some of the fundamentals of MATLAB. Chs 8,9, and 11 may be helfpul here.
Thanks Cris.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

태그

질문:

2021년 3월 31일

편집:

2021년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by