(Matlab) How can I make 3D plot from 2D experimatal data? [duplicate] - matlab

This question already has an answer here:
3d plot with given 2d data
(1 answer)
Closed 8 years ago.
There are 2D experimental data.
z=load('data.txt');
x=z(:,1);
y=z(:,2);
plot(x,y)][1]
I want to make it to 3D as the link did.
Here is a link. 3d plot with given 2d data

The question and answer is a bit misleading, since the question is actually not regarding data but the bell function (or triangular function). They are symmetric and have corresponding 2D versions (see: http://en.wikipedia.org/wiki/Gaussian_function#Two-dimensional_Gaussian_function).
y=exp(-x.^2/2); %1D
z=exp(-(X.^2+Y.^2)/2); %2D
In general, however, this is not the case. Your data, for instance, is not 2D:
z=load('data.txt');
x=z(:,1);
y=z(:,2);
x is 1D and y is your dependent variable. If x and y were independent you would have a third variable (e.g. z):
x=[0,1,2];
y=[0,1,2];
z=[1,2,3;
2,2,2;
3,2,1];
The entries in z would then be z(x,y) (e.g. z(3,3)=1).
To sum up the confusion:
When you plot a 1D function it is plotted in 2D (x,y),
and when you plot a 2D function it is plotted in 3D (x,y,z), (x,y,colors) or (x,y,z and colors) (the latter is what is used in the mentioned question).

Related

Is there a way in matlab to plot several 1D courves on specific coordinates over a 3D mesh?

For example, I got 3 pairs of 1-D loglog curves and additionally their associated cartesian coordinate points (x,y,z) of one of their ends A, B and C over a mesh surface S (z is positive downwards and linear but coincides in direction with the log(y)-axis from the curves). Is it possible to respresent in a single figure such system of plots in matlab?
Moreover, obtain an interpolated slice from A,B and C?
The images from the question of user3281667 gives an insight of what we are trying to do here:
https://gis.stackexchange.com/questions/252939/interpolating-xyz-data-in-arcgis-3d-analyst
Thanks.
Kind of solved. First we need to know in which format is our data, this case scattered.
I concatenated a nx4 matrix with the preprocessed data A=[X Y Z C].
Then use the right tools, to plot use scatter3: scatter3(A(:,1), A(:,2), A(:,3),30, A(:,4), 'filled' )
Now to interpolate, fisrt generate a grid refinement with meshgrid: [Xm, Ym, Zm] = meshgrid(min(X):2:max(X), min(Y):2:max(Y), min(Z):2:max(Z)) next interpolate using griddata Cm = griddata(X,Y,Z,C,Xm,Ym,Zm);and last plot again.
figure
scatter3(Xm(:), Ym(:), Zm(:), 30, Cm(:), 'filled' )
Thanks to user7431005

How to plot from adjacency matrix? [duplicate]

This question already has an answer here:
Draw network or graph from matrix in matlab
(1 answer)
Closed 7 years ago.
I have an adjacency matrix and corresponding labels. I need to plot a network with weighted edges and different colors based on labels. I found there is gplot function in matlab, but it is not created weighted edges. Does anyone know any toolbox or function or something I can use?
There is a tool called wgPlot by Mike Wu that will allow you to plot weighted adjacency graphs easily.
wgPlot by MikeWu
Note that the edges are not labeled textually, but by a color scale.

Interpolating 3D points from input points corresponding to a closed surface

I have a list of scattered 3D points similar to the one below:
Using MATLAB, I want to interpolate further points from the surface that those original points correspond to, in order to obtain a more complete scatter. Note that there are no particular slices defined on this scattered data. That is, the z values of the point cloud are not discrete, so it's not possible to interpolate slice by slice.
I think that the ideal way to achieve this would be to somehow obtain the smooth closed surface which best matches the scattered data, and then sample it. But I have found no straightforward way to achieve this.
The scatterinterpolant class could be a simple option.
Use scatteredInterpolant to perform interpolation on a 2-D or 3-D
Scattered Data set. For example, you can pass a set of (x,y) points
and values, v, to scatteredInterpolant, and it returns a surface of
the form v = F(x, y). This surface always passes through the sample
values at the point locations. You can evaluate this surface at any
query point, (xq,yq), to produce an interpolated value, vq.
http://au.mathworks.com/help/matlab/math/interpolating-scattered-data.html
Scattered data consists of a set of points X and corresponding values
V, where the points have no structure or order between their relative
locations. There are various approaches to interpolating scattered
data. One widely used approach uses a Delaunay triangulation of the
points.

How to plot a 3D figure in matlab based on a function like f(x,y,z)=0?

How to plot a 3D figure in MATLAB based on a function like f(x,y,z)=0?
And this complicated function can not be written as z = f(x,y).
f(x,y,z)=sum(a.*exp(sv(:,1)-x).^2+sv(:,2)-y).^2+sv(:,3)-z).^2)-b=0
where a is a known vector, sv is a known matrix, b is a known value. x,y,z are three variables. How to draw this surface in 3D way in matlab?
I just solve this question by this tool from the Matlab File Exchange:
Ezimplot3: implicit 3D functions plotter
your function only contains 1D vectors( I am assuming they are of equal lengths), if summed it will give you a constant; therefore, there is really nothing to plot.

Carpet plot with MATLAB

I have to create a carpet plot (or raster plot) with MATLAB. This plot represents the hourly electric consumption along a year.
In my actual implementation I have a m x n matrix (m is the hours in a day, n the days in a year) containing the consumption values. In order to obtain the carpet plot I use the surf function setting view(0,-90) .
The problem is that MATLAB represent each "cell" of the surface with a color that is related with the interpolation of the 4 consumption values around that "cell", whereas I need that each cell of the surface represent a single value of the matrix.
Is there a way to obtain, with MATLAB, what I need?
surf is for making 3-dimensional surface plots.
You want a 2-dimensional heat map - try looking at the output from help imagesc and help image.