Extract data for 3d plated grave

1 view (last 30 days)
Mo Nabil on 12 Apr 2022
Commented: Rik on 12 Apr 2022
Hello everyone!
i just started learing mathlab. i did plot a simple 3d graph of circles by this code ;
clear;
clc;
figure(1)
r=3;
th=0:180/30:360;
Lgt=length(th);
for height=0:4:20;
x=r*cos(th);
y=r*sin(th);
z= height* ones(r,Lgt);
plot3(x,y,z)
hold on
r=r+5;
end
hold off
when i came to extract the ploted graph 3d data i tried different way among them
ch=get(gca,'children')
X=get(ch,'Xdata')
Y=get(ch,'Ydata')
Z=get(ch,'Zdata')
which resulted in many many date, like repeated 20 20 20 many times while it should just gave me on raw of 20s one of 16s...0s
the same with x and y .
how to extract them correctly?

Rik on 12 Apr 2022
figure(1)
r=3;
th=0:180/30:360;
Lgt=length(th);
for height=0:4:20;
x=r*cos(th);
y=r*sin(th);
z= height* ones(r,Lgt);
plot3(x,y,z)
hold on
r=r+5;
end
hold off
ch=get(gca,'Children')
ch =
93×1 Line array: Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line Line
X=get(ch,'XData')
X = 93×1 cell array
{[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]} {[28 26.8848 23.6279 18.4889 11.8770 4.3190 -3.5830 -11.1996 -17.9240 -23.2207 -26.6676 -27.9901 -27.0830 -24.0185 -19.0407 -12.5461 -5.0521 2.8444 10.5143 17.3466 22.7971 26.4316 27.9605 27.2622 24.3921 19.5790 13.2063 5.7815 -2.1038 -9.8215 -16.7569 -22.3574 -26.1769 -27.9112 -27.4221 -24.7486 -20.1036 -13.8572 -6.5069 1.3617 9.1219 16.1554 21.9019 25.9038 27.8422 27.5627 25.0876 20.6140 14.4983 7.2277 -0.6187 -8.4158 -15.5425 -21.4311 -25.6124 -27.7536 -27.6839 -25.4089 -21.1098 -15.1292 -7.9434]}
As you can see, each circle in your plot is a separate line object. The get function will return a cell array with a cell element for each line. Since the x and y don't actually depend on your loop variable (and therefor could be computed outside the loop), you can just select one of them.
The ZData property contains 1 z value for every x and y. Otherwise it wouldn't be possible to plot them. If you're only after a single value, you could either select 1 value at random, or use unique (which will allow you to detect multiple heigths).
Z=get(ch,'ZData');
for n=1:numel(Z)
Z{n}=unique(Z{n});
end
Z
Z = 93×1 cell array
{[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]} {[20]}
Rik on 12 Apr 2022
You're welcome. If I solved your question, please consider marking my answer as accepted. If not, feel free to comment with your remaining issues.