Extract data from a 3D figure created by 'fimplicit3'

I am trying to extract the data from a 3D figure created by 'fimplicit3'. I found this is impossible for a 3D figure created by an implicit function using 'fimplicit3', while this works for a 2d figure produced by an implicit function using 'fimplicit'.
For a 2D one, we can extract it using: https://www.mathworks.com/matlabcentral/answers/100921-how-do-i-extract-data-points-from-a-plot#answer_110269. However, when I used the same method for a 3D figure, the following error occured:
mmm.png
I checked the figure 'Property' and 'Data' exists in a 2D figure, but not in a 3D figure.. Why cannot extract data for 3D figures like this? And any other method to do this? Thank you.

1 Comment

Matt J
Matt J on 19 Jun 2019
Edited: Matt J on 19 Jun 2019
Well, I can tell you it's not a question of 2D versus 3D. Surface plots, 3D line plots, and patch objects all have XData, YData, and ZData properties. ImplicitFunctionSurface seems to be a weird exception.
I assume the reason that ImplicitFunctionSurface objects don't store the Data forming the plot is that that Data is not fixed. You can get a whole different mesh simply by adjusting the MeshDensity property.

Sign in to comment.

Answers (1)

I had the same issue, and came up with three workarounds.
1) This is the simplest, and my preferred method, which I found after messing with methods #2, and #3 quite a bit. This problem turns out to be much easier if you don't use implicit plotting at all. Instead, generate a grid of points and values. These can be used to generate an isosurface, which plays nicely with all the other tools like patch.
x=-1:0.01:1;
y=-1:0.01:1;
z=-1:0.01:1;
[X,Y,Z]=meshgrid(x,y,z);
V=fun(X,Y,Z); % This is the function we want to plot, evaluated at each of the grid-points
I=isosurface(x,y,z,V,0) ;
% This retuns a handle to an object containing both vertices and triangular mesh
% connectivities for the isosurface at f(x,y,z)=0
2) Plot a series of 2D implicit surfaces by specifying values for the z-coordinate. Since 2D implicit surfaces have the XData, and YData accessible, this provides a method for gathering all the desired data. I wrote a function to do this in general, and attached it here.
After getting acceptible data this way, I ran into issues recreating the surface as a mesh over the points. While I'm sure this is possible, in my research, I discovered the much simpler method #1.
3) Using the matlab datacursor functionality to search for points on the surface
CM=datacursormode(gcf);
DT=cm.createDataTip(handle(Surface Object));
This generates a new datatip object DT attached to the surface object. You can then set the position by:
DT.Position=[x,y,z];
Default behavior is to snap to the surface at a point near the specified position, thus altering the position. This can then be read as:
[x,y,z]=DT.Position;
This method should be able to be used to scan the entire region to find valid points, then sort them to remove dupicates. I even went so far as to begin writing a function to do this, but then came up with the simpler method #2.

1 Comment

Hi, can you share the tool that can extract data points in method 1?

Sign in to comment.

Products

Release

R2019a

Asked:

on 19 Jun 2019

Commented:

on 9 Sep 2023

Community Treasure Hunt

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

Start Hunting!