I want to extract data from a figure similar to the figure in the answer of this question How can I adjust 3-D bar grouping and y-axis labeling in MATLAB?
I use the following MATLAB code, however it returns null for x, y, and z
x=get(findobj(get(gca,'Children'),'type','line'),'xdata');
y=get(findobj(get(gca,'Children'),'type','line'),'ydata');
z=get(findobj(get(gca,'Children'),'type','line'),'zdata');
Would you please help me to find the problem? It works for 2D plot but it does not work for a 3D plot like:
bar3([3 2 4;2 3 1]);
I do not understand why?
i also tried the following code:
D=get(gca,'Children');
XData=get(D,'XData');
YData=get(D,'YData');
ZData=get(D,'ZData');
in this case i get some answer for ZData which is a 3*1 cell, each cell contain an array of 12*4. still do not know how to extract the values and what is this cell?
As mentioned in the comments ZData has a regular pattern. Using the following code I could extract the data :
z=ZData;
a=z{1,1};
r=size(a,1);
num_rows=ceil((r-2)/6);
num_col=size(z,1);
result=zeros(num_rows,num_col);
m=0;
for i=size(z,1):-1:1
m=m+1;
z_i=z{i,1};
k=0;
for j=2:6:r
k=k+1;
result(k,m)=z_i(j,2);
end
end
end
result would be the data we are looking for.