How to display a saved .fig file in uiaxes appdesinger?
    16 views (last 30 days)
  
       Show older comments
    
    taimour sadiq
 on 28 Nov 2023
  
    
    
    
    
    Commented: Walter Roberson
      
      
 on 28 Nov 2023
            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
0 Comments
Accepted Answer
  Walter Roberson
      
      
 on 28 Nov 2023
        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 Comments
  Dyuman Joshi
      
      
 on 28 Nov 2023
				
  Walter Roberson
      
      
 on 28 Nov 2023
				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.
More Answers (0)
See Also
Categories
				Find more on Printing and Saving in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

