How to plot a graph on the app designer?

5 ビュー (過去 30 日間)
Prajwal Venkatesh
Prajwal Venkatesh 2020 年 2 月 3 日
編集済み: Adam Danz 2020 年 2 月 4 日
I have a figure saved which i want to plot on the UI axes on the app or just display on the app
How do i do that?
  3 件のコメント
Prajwal Venkatesh
Prajwal Venkatesh 2020 年 2 月 3 日
I have a fig file saved
Geoff Hayes
Geoff Hayes 2020 年 2 月 3 日
Have you looked at https://www.mathworks.com/matlabcentral/answers/100687-how-do-i-extract-data-from-matlab-figures? It may be easier to extract the data from the figure to a mat file and then load and plot that data on the UI axes of your app. I'm assuming that you want the figure to appear within the App and not as a separate window...

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

採用された回答

Adam Danz
Adam Danz 2020 年 2 月 3 日
編集済み: Adam Danz 2020 年 2 月 4 日
Use copyobj() to copy all of the children from your saved figure's axes to the UIAxes.
Here's a functional demo.
% Create a figure, save it, and close it.
mainFig = figure();
plot(magic(4),'-o')
savefig('MainFigure.fig') % use full path whenever possible; see fullfile()
close(mainFig)
% 1) Create a UIFigure and UIAxes (For app designer, skip this step)
% 2) Open the main figure in an invisible state.
% 3) Get the axis handle of the figure.
% 4) Copy all children of the axis handle to the UIAxes.
% 5) Close the invisible main figure.
% 1) Create UIAxes; Skip this step if you're using app designer.
app.UIFigure = uifigure();
app.UIAxes = uiaxes(app.UIFigure);
% 2) OPen the main figure, invisible.
figHandle = openfig('MainFigure.fig','invisible') % use full path whenever possible; see fullfile()
% 3) Get all axis handles that belong to the invisible figure
axesHandle = findobj(figHandle,'type','axes');
%4) Copy all children of the axis to your UIFigure.
% If there are more then 1 axes found on the invisible
% figure, this will only copy the first axes listed.
% Replace input #2 with your UIAxes handle
copyobj(axesHandle(1).Children, app.UIAxes);
% Close the invisible figure
close(figHandle)
To delete the demo figure from you system,
delete('MainFigure.fig')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by