Memming's Inconsistency
Nothing Personal, Yet Subjective
Blog | Guestbook
Keyword | Local | Tag
T 27 / Y 78 / Total 54293
Catergories
Calendar
«   2010/07   »
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tag
tip, MATLAB, vim, LaTeX, mathematics, Google, Tips, 촛불집회, derivative, conference wsom, theorem, CNEL, correlogram, ocw, equation search engine, algorithm, synchrony, spike train, coupled oscillator, javascript,
Archive
Link
Search
  submit
Recent Articles
Recent Comments
Recent Trackbacks
2006/07/26 15:34
Extracting Data from MATLAB figures
2006/07/26 15:34 2006/07/26 15:34
Today, my friend had a problem of rotating a figure 90 degrees clockwise for his paper.
But he only had the MATLAB figure, the ".fig" file, and no data.
The easy and elegant way to do it is to get the data points out of the figure and redrawing the figure.
So here we go.

In MATLAB, there are axes in a figure, and plot objects in an axis.
In the plot object, you can find the data. We can do this using only the 'get' method.

Suppose we have a figure like this, and want to restore data from the figure.
subplot(2,1,1); plot(1:10, sin([1:10]/5));
subplot(2,1,2); plot(1:10, sin([1:10]/3+2.4), 'k*');

First, we find the axes.

>> axs = get(gcf, 'Children')

axs =

  153.0011
  151.0012

That's right. The two strange numbers are the pointer to each axis.
Let's try to see what objects are in the first axis.

>> pos = get(axs(1), 'Children')

pos =

  154.0016

So there's one plot object in the axis. Let's see what properties it has.
>> get(pos)
                Color: [0 0 0]
            EraseMode: 'normal'
            LineStyle: 'none'
            LineWidth: 0.5000
               Marker: '*'
           MarkerSize: 6
      MarkerEdgeColor: 'auto'
      MarkerFaceColor: 'none'
                XData: [1 2 3 4 5 6 7 8 9 10]
                YData: [0.3970 0.0749 -0.2555 -0.5578 -0.7987 -0.9516 -0.9998 -0.9379 -0.7728 -0.5226]
                ZData: [1x0 double]
         BeingDeleted: 'off'
        ButtonDownFcn: []
             Children: [0x1 double]
             Clipping: 'on'
            CreateFcn: []
            DeleteFcn: []
           BusyAction: 'queue'
     HandleVisibility: 'on'
              HitTest: 'on'
        Interruptible: 'on'
             Selected: 'off'
   SelectionHighlight: 'on'
                  Tag: ''
                 Type: 'line'
        UIContextMenu: []
             UserData: []
              Visible: 'on'
               Parent: 153.0011
          DisplayName: ''
            XDataMode: 'manual'
          XDataSource: ''
          YDataSource: ''
          ZDataSource: ''
XData, YData, ZData are the data in the object. Yes, that's what we need!
Let's make another plot with 90 degrees CW rotation.
X = get(pos, 'XData');
Y = get(pos, 'YData');
figure;
plot(Y, fliplr(X));

Consult MATLAB documentation 'Handle Graphics' for details.
TAG :
Trackback : http://blog.memming.com/trackback/8
mileva (2008/03/10 16:01)
thank you.. I am constantly making figures and forgetting to save the original data, this was a huge time saver for me

Andy (2009/01/05 14:31)
I appreciate you posting this. It is very helpful!

Max (2009/08/10 10:02)
Thanks a lot ... very helpful

Adi (2009/08/10 15:22)
Thanks a lot. above explained procedure was of great help to extract data from .fig files.

Albert (2009/08/19 17:47)
Wonderful, wonderful! Thanks a lot

Adam (2009/09/16 07:28)
Wonderful. Clearly explained, De-stressed me no end :D

Edith (2009/11/02 23:05)
Many thanks!!!

Sas (2009/11/17 04:25)
Helped me a lot.
Thank you.

Secret visitor (2009/12/01 21:34)
Administrator only.

srimalj (2009/12/01 21:35)
Awesome.

My plot is a contour/surface plot.

When I do the above for that I get ,

>> X = get(pos, 'XData')

X =

0 1

>> Y = get(pos, 'YData')

Y =

0.3047 0.8953

What am I missing?

Thanks

doresoom (2010/01/07 10:04)
try pos=get(axs(2),'Children')

Hovden (2010/05/18 16:03)
Great Post. Concise and clear.

Name   Password   Home   Secret   Submit
 Prev   1  ...  25   26   27   28   29   Next 
memming’s Blog is powered by Tattertools.com / Designed by faido