Clear Filters
Clear Filters

Extract data from polar plot [example.fig]

35 views (last 30 days)
I recieved a series of polar plots [Example_n.fig, with n = (1000:1:1250)] for 36 headings. Now, I would like to extract the data of these plots to matrices, so i can import the data in excel.
So I used the following code, which does open the figure and work for simple x,y - plots, but doesn't extract the data from the polar plots.
open 'Example_n.fig'
D=get(gca,'Children');
XData=get(D,'XData');
YData=get(D,'YData');
Data=[XData' YData'];
Thanks in advance!

Answers (3)

dpb
dpb on 28 Nov 2018
Edited: dpb on 28 Nov 2018
Well, a variant of that works ok here with the example polar plot in the documentation.
>> hF=openfig('polar.fig');
>> hAx=gca;
>> hL=findobj(hAx,'Type','Line');
>> XY=[hL.XData.' hL.YData.'];
>> whos XY
Name Size Bytes Class Attributes
XY 629x2 10064 double
>>
The problem you're having is that probably the plot was created with the new(ish) polarplot function rather than with polar. With it the data properties are RData and ThetaData instead of X/YData.
Everything above still works except use
RTh=[hL.RData.' hL.ThetaData.'];
after finding the line handle.
  5 Comments
dpb
dpb on 29 Nov 2018
Edited: dpb on 29 Nov 2018
What release are you using? The new polarplot wasn't introduced until R2016x, but a test here w/ R2014b failed to be able to load a figure created with it as expected.
The error message about RData is the expected one if the plot was created by the venerable polar plot routine; the line object created by it doesn't include the polar coordinate properties.
The symptom with X/YData I can't seem to reproduce by any machination with either release or particular plotting function, however. With the polarplot object, XData/YData are empty here with R2016b/R2017b but that plot type can't be created w/ R2014b at least by openfig trying to read a .fig file created by the later releases I have.
Maybe one of the R20YY releases has a bug I can't recreate???
dpb
dpb on 29 Nov 2018
How about attaching one of the files that cause you the problem -- then folks here can see if have similar symptoms or isolate something unique to your particular system.
Also, if you can, see if the creator of the .fig files can tell you which release was used to create them as well as the release you're using. Oh--and OS on which running each would possibly be of interest/significance.

Sign in to comment.


Jochem Oostenbroek
Jochem Oostenbroek on 29 Nov 2018
Hi DB,
Thanks for the tips. When using your lines, I get the following error
>> RTh=[hL.RData.' hL.ThetaData.'];
No appropriate method, property, or field
'RData' for class
'matlab.graphics.chart.primitive.Line'.
But for using the XData and YData, Matlab returns the error:
"Too many input arguments", which doesn't really make sense to me.
What do you reckon?

Hannes Morgenroth
Hannes Morgenroth on 29 Mar 2022
Had the same issue and for me the solution was as simple as using 'RData' and 'ThetaData' instead of 'XData'and 'YData'.
%find the handle
ax=gca;
h = findobj(ax,'Type','Line');
%get the data (dot notation instead of get() for readability)
r=h.RData;
theta=h.ThetaData;

Categories

Find more on Polar Plots in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!