Matlab 3D Matrix Plot [duplicate] - matlab

This question already has answers here:
Plotting 3-D Matrix *values* in MATLAB
(2 answers)
Closed 7 years ago.
Ive created a 3d matrix in MATLAB. The values of the matrix are the velocity at that point in a rectangular section. I would like a plot with colours showing the values at each position, is this possible?
Phrasing this another way, I have a matrix of size 100x100x200. Id like a graph that has 100x100x200 points and the colour of each of those points is related to its value.

This question is very similar to this question. You might want to check it out.
UPDATE:
Suppose you have a 3D matrix A:
A = rand(100,100,200);
You want to plot each entry of A mapped to a color at its 3D coordinates. First generate the coordinates:
[x,y,z] = meshgrid(1:100,1:100,1:200);
Now you are ready to use scatter3:
scatter3(x(:),y(:),z(:),5,A(:))
Here the : indexing vectorizes the coordinates column-wise.
Hope this helps.

Related

Equivalent of Mathematica's ListDensityPlot[] function for Matlab [duplicate]

This question already has an answer here:
Density plot in Matlab
(1 answer)
Closed 6 years ago.
Mathematica's ListDensityPlot[] can take a list of 3D coordinates, where the 3rd coordinate is a scalar, call it temperature or concentration etc. and return a density plot. The list would look something like
temperature={{0,0,20},{0,1,25},...,{9,9,35}}
in Mathematica notation.
Mathematica automatically interpolates (I guess) over the values so it returns a continuous, smooth picture with a color scale to describe the scalar values on the 2D plane.
Is there anything equivalent to this in Matlab?
Thanks
You can use the Delaunay triangulation function of your planar points, then generate a surface over the triangulation.
It would look something like this:
Points=[xpoints, ypoints, zpoints];
tri=delaunay(Points(:,1), Points(:,2));
figure
trisurf(tri, Points(:,1), Points(:,2), Points(:,3))
shading interp
colormap jet
colorbar EastOutside

Matlab multidimensional scatter [duplicate]

This question already has answers here:
3D scatter plot with 4D data
(2 answers)
Closed 7 years ago.
I have a an nx4 matrix where each row is an observation.
The three three columsn represent by variables, and the fourth a 'fitness' parameter.
I would like to show this in a 3D scatter plot, where each axis is one of my variables and then color each point depending on how close to one of the extremes in my fourth column it is.
For example, say fitness ranged between 0 and 1. I would want observations with fintess 0 to be blue, those with fitness 1 to be red and those in-between some corresponding shade.
Any advice on how best to do this?
Thanks!
The function scatter3 has a color input argument. But you need to define the size of the markers also.
% Generate example data,
X=rand(10,1)*10;
Y=rand(10,1)*3;
Z=rand(10,1)*5;
fit=rand(10,1)*3+10;
scatter3(X,Y,Z,ones(size(X))*40,fit,'fill')
Use scatter3 with an appropriate colormap:
scatter3(data(:,1), data(:,2), data(:,3), 10, data(:,4), '*')
colormap(hsv)
colorbar
where
data is your matrix
10 is markersize
'*' is the marker shape
hsv is the selected colormap

How to plot elements in the matrix on the graph? MATLAB [duplicate]

This question already has an answer here:
How to create 3D-Plot in MatLab?
(1 answer)
Closed 8 years ago.
I have just started MATLAB. So please help me.
If I have a m*n matrix.
I want to plot a 3-d plot with x-axis and y- axis as x indices and y indices respectively. And on the z axis, element at i,j in the matrix.
How to plot it in MATLAB?
Say your m*n matrix is A
You can plot the data as a surface by calling
figure %# opens a new figure, otherwise you'll overwrite an existing one
surf(A)
If you want to add x- and y- indices
surf(xIndices, yIndices, A)
If you want a scatter plot, you need to create arrays of the same size as A for the coordinates first
[xx,yy] = meshgrid(xIndices, yIndices);
plot3(xx(:), yy(:), A(:), 'o');
or
scatter3(xx(:), yy(:), A(:))

Creating surface in 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.

Plot points (x,y) and use a third (z) as the color code in Matlab [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
matlab: scatter plots with high number of datapoints
I have 3 vectors of 315,000 elements each. X,Y, and Z. X & Y are coordinates and Z is a value. I must plot the coordinates as points in a 2D graph, the Z is a color indicator at each coordinate of X and Y. I've tried the "scatter" command, but it extremely slow. Would anybody suggest a better way?
thanks!
Depending on what kind of color map you are looking for, you can try something like
zmin=min(Z);
zmax=max(Z);
map=colormap;
color_steps=size(map,1);
hold on
for i=1:color_steps
ind=find(Z<zmin+i*(zmax-zmin)/color_steps & Z>=zmin+(i-1)*(zmax-zmin)/color_steps);
plot(X(ind),Y(ind),'o','Color',map(i,:));
end
The finding is a little expensive but it seems to be quicker than scatter. I'm sure you could optimize this further.
Try cline from MATLAB file exchange here. It looks like it does exactly what you want.
Your code is slow because of the large size of the vectors, not because of the SCATTER function. Try breaking them down into vectors of smaller size (say, 10 elements each) and putting each vector into a cell of a cell array. Then loop through the cell array and scatter each smaller vector individually to avoid loading too much into the memory.
hold on
for i=1:numel(XcoordCellArray):
scatter(XcoordCellArray{i},YcoordCellArray{i},S,ZcoordCellArray{i})
end