How do I get the Xdata and Ydata from a figure using MATLAB 2015b?

Recently upgraded to Matlab 2015b and the handle graphics seems to have changed from the older versions. How do I get the Xdata and Ydata from a figure?

 Accepted Answer

It’s changed, but it’s still available:
figure(1)
plot(x, y) % Plot Your Favourite (x,y) Values
grid
savefig('TestFig.fig');
clearvars, clf, cla % Be Certain All Are Cleared
openfig('TestFig.fig');
hp = findobj(gca,'Type', 'line');
xd = get(hp, 'XData');
yd = get(hp, 'YData');

4 Comments

Thanks! I was using 'Axes' instead of 'line'. The help is much appreciated!
My pleasure!
A get call to gca used to work. I discovered the ‘new’ findobj requirement when I needed to get the data from .fig files uploaded here. I’m not sure that’s well-documented.
Dummy question: how can you update XData and YData after e.g. cleaning up raw data?
set(??)
Not ‘dummy’ at all!
I would just re-plot them.
However you can always do something like this as well:
set(hp, 'XData',newXdata);
set(hp, 'YData',newYdata);
Note that I did not test that, however it should work.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

CB
on 10 Sep 2015

Commented:

on 28 Sep 2020

Community Treasure Hunt

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

Start Hunting!