MATLAB Answers

2

How do I extract data points from a plot?

I would like to extract data points from a plot.

Tags

Products

6 Answers

Answer by MathWorks Support Team on 27 Sep 2016
 Accepted Answer

In order to retrieve data values from a plot follow these steps:
1. Open the figure
2. In the MATLAB Command Window type the following commands:
h = findobj(gca,'Type','line')
x=get(h,'Xdata')
y=get(h,'Ydata')
Note that the dot notion feature is available starting from MATLAB 2014b, so instead of using the "get" function, you may do the following
x = h.Xdata;
y = h.Ydata;
In this example the plot was a plot of a line. The FINDOBJ function locates graphics objects with specific properties, for more information on this command type:
web([docroot,'/techdoc/ref/findobj.html'])
at the MATLAB Command Window.
If you have more than one line on the plot, the GET function will return a cell array. To retrieve the numbers inside of this cell array, use indexing. For example, to retrieve the points in the first line,
>> x{1}
>> y{1}
Or, if the lines have the same number of points, use the CELL2MAT function. Following the example above, to retrieve the numbers inside of cell array 'x' use:
X2=cell2mat(x)

  4 Comments

Show 1 older comment
The dot notion feature is available starting from MATLAB 2014b, so instead of using the "get" function, you may do the following
x = h.Xdata;
y = h.Ydata;
Thank you ver much. This is the easier way.
Hello
I have a plot which has two lines each from different sensor. The plot has time in X-axis and sensor values in Y-axis. I have to find what is the value each sensor giving at a time i.e for a value on X-axis, I have to find corresponding Y-axis valus for the both the lines(or sensors).
This code gives data from both the lines but the correspon to different time(or X-axis) value.

Sign in to comment.


Answer by Jhonantans Rocha on 25 Aug 2014

Man, this really help me. Thanks!

  0 Comments

Sign in to comment.


Answer by MANIMARAN SELVAM on 2 Nov 2015

how to extract points from the output PV and IV graph

  1 Comment

Your meaning is not clear. I have asked for more information in the Question you started about this http://uk.mathworks.com/matlabcentral/answers/252343-how-can-i-get-points-table-from-output-graph-in-matlab

Sign in to comment.


Answer by Stefanos Doltsinis on 16 Apr 2016

that code works nicely!
I just have one issue. I want to extract data from a subplot(2,1) and the extracted data are only from the second plot. How can I receive data from the first plot?
@MANIMARAN SELVAM I want to extract data from the same plot as you want (Photovoltaic array simulink module) and the code above works fine. At least for the Power against Voltage diagram. The data you need will be in x in the form of an array and will have the following sequence x{1} is the maximum voltage x{2} is the maximum power x{3} are all the data points on the graph.
I hope this helps.

  1 Comment

In the above code, replace the line
h = findobj(gca,'Type','line')
with
h = findobj(subplot(2,1,1),'Type','line')

Sign in to comment.


Answer by swagatika panigrahi on 13 Feb 2017

How to extract if the data points are defined using triangle or square symbol...I want to find the xdata and ydata at 'triangle and ''square' point on d figure

  3 Comments

Which plotting calls were used?
ax = gca;
obj_with_xd = findobj(ax, '-property', 'XData');
obj_with_right_markers = findobj(obj_with_xd, 'Marker', '^', '-or', 'Marker', 'v', '-or', 'Marker', 's');
the_xd_cell = get(obj_with_right_markers', 'XData');
if ~iscell(the_xd_cell); the_xd_cell = {the_xd_cell}; end
the_yd_cell = get(obj_with_right_markers, 'YData');
if ~iscell(the_yd_cell); the_yd_cell {the_yd_cell}; end
Now the_xd_cell and the_yd_cell are cell arrays containing the xdata and ydata of the objects that have markers v (downward triangle) or ^ (upward triangle) or s (square).
Hello @Roberson! I have a figure of ECG signal. In this signal, I detect RQS point and after detecting this point I use the different sign for pointing this graph. Now I want to extract the value of this detected point in that way, such that: R1: X-level: 42, Y-level: 0.908 again R2: X-level: 137, Y-level: 0.854 and so on for all detected point of RQS (Q1, Q2...). How can I do that? I also attached my figure in this comment also. After finding this value I also want to save this value in a text file.
Help me.

Sign in to comment.


Answer by Akshay Kumar on 8 Jul 2018

I am facing difficulties in accessing the plot data using the above method. The plot is generated using EEGLAB toolbox. The plot has 42 lines, however, after following the above mention step, the x_data and y_data do not contain the required data. Please advice.

  0 Comments

Sign in to comment.