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

 Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 31 Mär. 2021
Bearbeitet: Cris LaPierre am 31 Mär. 2021

0 Stimmen

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 Kommentare

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 am 31 Mär. 2021
Bearbeitet: Cris LaPierre am 1 Apr. 2021
Consider going through MATLAB Onramp to learn some of the fundamentals of MATLAB. Chs 8,9, and 11 may be helfpul here.
Thanks Cris.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu App Building finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by