Extracting data from Contour plots
이전 댓글 표시
I am trying to extract data from a contour plot. I managed to get all the information about the dataObjs using
open('colormapinhomo.fig');
h = gcf;
axesObjs = get(h, 'Children');
dataObjs = get(axesObjs, 'Children')
dataObjs{2}
Contour with properties:
LineColor: [0 0 0]
LineStyle: 'none'
LineWidth: 0.5000
Fill: 'on'
LevelList: [1×62 double]
XData: [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 32 33 34 35 36 37 38 39 40]
YData: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
ZData: [20×40 double]
but cant get the data itself. Any help ? And is this the only way to extract data, or can I somehow output a .dat file of the figure with the data whether it was a contour or a histogram or even a simple plot line ?
댓글 수: 2
Adam
2017년 5월 18일
dataObjs{2}.XData
dataObjs{2}.YData
dataObjs{2}.ZData
is the data. Generally you should keep hold of the data when you plot because extracting data from a plot is silly when you can just use the original data. If you've lost the original data though then the above is the best you can get from the plot.
Adam Danz
2020년 1월 23일
Also see this file exchange function that extracts the coordinates of all contour lines and organizes them in a table by level.
채택된 답변
추가 답변 (1개)
Walter Nagy
2021년 4월 17일
편집: Walter Nagy
2021년 4월 17일
Try this code.
[c2,h2] = contour(xi,yi,zi,...); % your contour plot
c_lev=h2.LevelList; % get all contour levels
ind=find(c2(1,:)==max(c_lev)-1); % find index to the contour level of interest (one below the max in this case)
n_points=c2(2,ind); % number of points along the contour
contour_points=[c2(1,ind+1:ind+n_points) ; c2(2,ind+1:ind+n_points)]; % x, y coordinates of contour points.
pgon=polyshape(contour_points(1,:),contour_points(2,:)); % plots contour shape
[ac, bc]=centroid(pgon); % finds centroid of contour
댓글 수: 1
Fereshteh
2022년 7월 2일
Hello
I need to find centroid of contour but I dont have "polyshape" in my matlab. Is it in new version of matlab?
How can I find this Function?
Thank you.
카테고리
도움말 센터 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

