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 件のコメント

Natasha Vakharia
Natasha Vakharia 2021 年 3 月 31 日
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.
Cris LaPierre
Cris LaPierre 2021 年 3 月 31 日
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.
Natasha Vakharia
Natasha Vakharia 2021 年 4 月 1 日
Thanks Cris.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by