pixie
pixie

Reputation: 517

Extract surface from matlab .fig

I have a matlab .fig file which contains some points and a surface fitted to them. I want to extract the surface from the figure, and I would like to have both the vertices and the faces. Could you please provide me some hints on how to achieve this?

My figure can be found here: https://drive.google.com/file/d/0By376R0mxORYU3JsRWw1WjllWHc/view?usp=sharing and I would like to extract the surface without the blue points.

EDIT: it is not a duplicate, see my comment below as to why.

Upvotes: 1

Views: 569

Answers (1)

il_raffa
il_raffa

Reputation: 5190

The data used to plot either the surface and the dots are stored in the figure.

Therefore you can:

  • open the figure
  • get the data from the figure
  • get the children of the figure, in thsi case the axes
  • extract form the axes, the X, y, and z data of the surface

The axes actually contains two set of data:

  • the data of the dots stored in the z(1) XData, YData, ZData
  • the data of the surface stored in the z(2) XData, YData, ZData

This is the code (with "dot notation"):

% Open the figure
open('cubicinterp.fig')
% Get the data from the figure
x=gcf
% Get the children of the figure (in this case the axes)
y=x.Children
% Get the data used to plot on the axes
z=y.Children

figure
XX=z(2).XData;
YY=z(2).YData;
ZZ=z(2).ZData;
CCDD=z(2).CData;
surf(XX,YY,ZZ,CCDD)
return

This is the code without the "dot notation" (before R2014b)

% Open the figure
open('cubicinterp.fig')
% Get the data from the figure
x=gcf
% Get the children of the figure (in this case the axes)
y_1=get(gcf,'children');
% Get the data used to plot on the axes
z_1=get(y_1,'children');

figure
XX=get(z_1(2),'xdata');
YY=get(z_1(2),'ydata');
ZZ=get(z_1(2),'zdata');
CCDD=get(z_1(2),'Cdata');
surf(XX,YY,ZZ,CCDD)

This is the extracted surface:

enter image description here

Hope this helps.

Qapla'

Upvotes: 2

Related Questions