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

조회 수: 3 (최근 30일)
taimour sadiq
taimour sadiq 2023년 11월 28일
댓글: Walter Roberson 2023년 11월 28일
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 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에서 Annotations에 대해 자세히 알아보기




Community Treasure Hunt

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

Start Hunting!

Translated by