Creating surface in matlab - matlab

I have a variable named say P which is simply a n*3 matrix. It stores x,y,z coordinates for a contour plot, its like a closed loop. Now I have several matrices like P which slice my object. What I would like is to create a surface using these contour points. scatter3() does not really give a good representation. The issue using surf() is that since I have contour coordinates, the coordinates are unordered. So the plot obtained using surf() is not the actual closed surface of my figure. How can I resolve this? Let's brainstorm.

Related

Embedding 2d plot into a 3d plot in matlab?

I have a set of data vectors z that has this 2d plot
How would I go about embed this set of data into a 3d plot like this in matlab? I'm asking for advice and suggestions. The theory I'm trying to employ is "for each data vector~zj, “copies” the data vector intothe first two entries of a 3D data vector~yjand then computes the squared length of~zj as the third entry of~yj. " or kernel trick.
Your 2d data will somehow be in the form, that you have x-coordinates and y-coordinates. Let's say you have a vector x and a vector y for simplification.
As you found out the plot3-function proivdes functionality to plot arbitrary points in 3d without the need of generating a mesh. What you need additionally is a third vector z with data for the 3rd dimension.
So what else can you do? The thing I am thinking about is rotating the plane you are plotting you "2d" data:
Rotational matrices can be seen here:
https://en.wikipedia.org/wiki/Rotation_matrix

How to surround data with an ellipse

Suppose that I am plotting different vectors of data with different dimensions in the same plot (x1,y1), (x2,y2) and I would like to surround this data with an ellipse, one ellipse for the (x1,y1) and another for (x2,y2). Can Matlab do it, or is it impossible?
And if this can be done with Matlab, can I also for some reasons, let one of the point of this data (x1,y1) lie outside the ellipse?

matlab - plot inequality in 3d with surf

I want to plot an inequality in 3d using surf. My condition is
0<=x<=1
0<=y<=1
0<=z<=x/(1+y)
I can create a surface plot using the following commands
[x y]=meshgrid(0:0.01:1);
z=x./(1+y);
surf(x,y,z);
This plot gives me regions where z=x/(1+y) but I am interested in regions where 0<=z<=x/(1+y) over all values of x and y. However, I am unable to plot/color the region explicitly. Can you please help.
A similar question has been asked but there was no acceptable answer and my question is also different.
Using isosurface you can show the boundary. There are two options, first create the points
[X,Y,Z]=meshgrid(0:.01:1);
then plot the boundaries in the z-direction (i.e. Z=0 and Z=X./(1+Y))
isosurface(X,Y,Z,Z.*(X./(1+Y)-Z),0)
or plot all the boundaries (including X=0, X=1, Y=0 and Y=1)
isosurface(X,Y,Z,Z.*(X./(1+Y)-Z).*X.*(X-1).*Y.*(Y-1),0)
All you have to do is come up with a function that is constant on any boundary, its value inside or outside is irrelevant as long as it is not zero.

How to plot 4D contour lines (XYZ-V) in MATLAB?

I have dataset of XYZ as the coordinates and V as the value at each point (100x4 matrix).
I plot the 3D surface using patch. (by faces & vertices)
How can I plot the contour lines of V (NOT Z) over the 3D surface !?
( The Contour3 function plots 3D contour lines of Z ; But I need contour lines of V. )
Actually I want something like this or this.
Thanks a billion for your help.
Well actually I found out that the isosurface command is exactly what I want.
However, this command requires the V data to be a 3D matrix. But my V is a vector. And the data in it is completely non-uniform and irregular. Now here rises a new question :
How can I convert this non-uniform vector to a 3D matrix, so that it's ready to be used with isosurface command !!?
Please help me with this.
cont3d from MathWorks FileExchange is not exactly what you're looking for, but it may give you some ideas.

plot a set of 3D data in different angles in MATLAB

I have a formula that depends on theta and phi (spherical coordinates 0<=theta<=2*pi and 0<=phi<=pi). By inserting each engle, I obtained a quantity. Now I have a set of data for different angles and I need to plot the surface. My data is a 180*360 matrix, so I am not sure if I can use SURF or MESH or PLOT3. The figure should be a surface that include all data and the axes should be in terms of the quantity, not the quantity versus the angles. How can I plot such a surface?
I see no reason why you cannot use mesh or surf to plot such data. Another option I tend to use is that of density plots. You basically display the dependent variable (quantity) as an image and include the independent variables (angles) along the axis, much like you would with the aforementioned 3D plotting functions. This can be done with imagesc.
Typically you would want your axes to be the dependent variables. Could you elaborate more on this point?
If I understand you correctly you have calculated a function f(theta,phi) and now you want to plot the surface containing all the points with the polar coordinated (r,theta,phi) where r=f(theta,phi).
If this is what you want to do, the 2D version of such a plot is included in MATLAB under the name polar. Unfortunately, as you pointed out, polar3 on MatlabCentral is not the generalization you are looking for.
I have been able to plot a sphere with the following code, using constant r=1. You can give it a try with your function:
phi1=0:1/(3*pi):pi; %# this would be your 180 points
theta1=-pi:1/(3*pi):pi; % your 360 points
r=ones(numel(theta1),numel(phi1));
[phi,theta]=meshgrid(phi1,theta1);
x=r.*sin(theta).*cos(phi);
y=r.*sin(theta).*sin(phi);
z=r.*cos(theta);
tri=delaunay(x(:),y(:),z(:));
trisurf(tri,x,y,z);
From my tests it seems that delaunay also includes a lot of triangles which go through the volume of my sphere, so it seems this is not optimal. So maybe you can have a look at fill3 and construct the triangles it draws itself: as a first approximation, you could have the points [x(n,m) x(n+1,m) x(n,m+1)] combined into one triangle, and [x(n+1,m) x(n+1,m+1) x(n+1,m+1)] into another...?