How to display a saved .fig file in uiaxes appdesinger?

10 次查看(过去 30 天)
i have some .fig plot save in my folder and i want to display them in UIAxes Appdesinger.. My code is
Path = 'C:\Folder\';
My_Fig = dir(fullfile(Path,'*.fig');
% Till here i have succesfully read all figures, now i want to display first figure in uiaxes appdesinger
imshow(My_Fig(1),'parent',app.UIAxes); % Not Works >> i have also tried openfig, imread etc

采纳的回答

Walter Roberson
Walter Roberson 2023-11-28
You cannot do that. A fig file is a saved figure or saved uifigure. Saved figures and uifigures are windows with attached behavior. You cannot display a complete window with behavior inside part of another window.
What is potentially possible is to copy objects from an axes in the figure, copying them into the new figure of uifigure. This will not copy all of the behavior (but might copy some of it). It risks not copying colorbars or legends or annotations. It also has a problem if the saved figure has more than one axes.
  2 个评论
Dyuman Joshi
Dyuman Joshi 2023-11-28
OP can use exportgraphics to save the contents of the graphics object and then use imshow.
Walter Roberson
Walter Roberson 2023-11-28
ProjectPath = 'C:\Folder\';
My_Figs = dir(fullfile(ProjectPath,'*.fig');
if isempty(My_Figs); error('No fig files in "%s"', ProjectPath); end
figfilename = fullfile(My_Figs(1).folder, My_Figs(1).name);
fig_to_copy = openfig(figfilename);
ax_to_copy = fig_to_copy.CurrentAxes;
After that you start needing to get into the code I posted at https://www.mathworks.com/matlabcentral/answers/262265-duplicating-an-imshow-image-into-a-new-figure-without-using-imshow#comment_332459 to copy the children of ax_to_copy, and to extract properties from the axes, filter the property names down to the ones that are settable, then copy the other properties to the new axes.
If the source axes to copy is already a uiaxes then it is a lot easier to copy the existing axes into the uifigure using copyobj() and then set the Position property of the newly-copied axes to the position that you wanted the uiaxes to be displayed at.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by