MATLAB MATLAB : how to get the data from a .fig file ?

  • Thread starter Thread starter serialtom
  • Start date Start date
  • Tags Tags
    Data File Matlab
AI Thread Summary
To extract data from .fig files in MATLAB and plot multiple curves on a single figure, the process involves using the "hold on" command to overlay plots. Start by opening a .fig file with the uigetfile function, then access the figure's axes and retrieve the data using the get function. Specifically, use get(gcf, 'Children') to obtain the axes and get(axs(n), 'Children') to access the plotted data. Store the X and Y data from each figure and repeat this for all .fig files. Finally, create a new figure, use "hold on" to overlay the plots, and plot each dataset with distinct colors for clarity. This method allows for effective visualization of multiple datasets in one figure.
serialtom
Messages
1
Reaction score
0
MATLAB : how to get the data from a .fig file ?

Hello everybody !

I ve a problem on MATLAB : I have 5 .fig files generated and I want to plot all the curves on 1 unique .fig file can u tell me how to do or how to get the data from one .fig file ?

thanks a lot

serialtom
 
Physics news on Phys.org
use the command "hold on" to plot all your data onto one figure area. Then "hold off" to make a new figure in a new area.
 


[filename,directory]=uigetfile()
picture=open([directory,filename])
axs=get(gcf,'Children')
% you may have to start poking around at the different axs(n) to get the right one
pos=get(axs(2),'Children')
% same with the pos(n), especially if you labelled your plots or have more than one line
x1=get(pos(1),'Xdata')
y1=get(pos(1),'Ydata')

repeat this process for all the .fig files you have, naming each successive one x2 and y2, or whatever you choose then...

figure
hold on
plot(x1,y1,'-b')
plot(x2,y2,'-r')
...
plot(xn,yn,'-k')
 

Similar threads

Replies
1
Views
2K
Replies
4
Views
1K
Replies
5
Views
2K
Replies
5
Views
2K
Replies
5
Views
3K
Replies
2
Views
3K
Back
Top