Can Matlab do a 3D plot with a 4th variable as color map? - matlab

I'm exploring contour3 and mesh, but don't see any path to take 3 variable data (x, y, z) and another variable (e.g. a = fn(x, y, z)) that can be used to create a heat map or colored contour plot in that 3D space.
Please point me in the right direction.

Related

Stress 3D Surface Plot in Matlab

I wrote a finite element program in Matlab which calculates the stresses of a 3D plate.
Now I would like to print these stresses but it is really hard to do for me. For each gauss point I can have the XYZ associated coordinate with its stress.
How can I do a plot like the ones I see in the FE software in Matlab? Currently what I can do is to plot a colour for the XYZ point assigning a colour range to the stresses. My result is a scatter plot.
I would like to have something like this
Thank you for your help!
Matlab has a surf(X, Y, Z, C) function that can take a color argument (C). Without the C argument, it uses the Z value to color the surface.
[X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
C = X.*Y;
surf(X,Y,Z,C)
The color is set using your active colormap.
If you want more control over the colors,
C can also be a MxNx3 array where the C(M, N, :) gives the RGB value of the color at the MxNth point.

Filling area of multiple contour plots that satisfies a condition in MATLAB

I have a 3D data, the x and y axis are angles and the Z axis is output. so the data is like this: [angle1 x angle2 x Z] ... I have multiple Z values at different conditions as well. Let's assume different Z values for 10 different conditions.
I want to plot a 3D contour of all the Z values overlaid on top of each other and at the same time fill the areas of each contour where Z<=-1 with a desired color ... How is that possible in MATLAB?
I found a way to overlay all the Z values on top of each other using a single color and contour command but I cannot find any way to fill the areas of Z<=-1 ... I realized that in contour command, MATLAB actually fill the whole graph with colors, so "hold on" command does not work here!
Here is an example image I want to create
Below is the example I could create but I cannot create the colored plot

How to make a 2 dimensional colormap for scatter point plot in matlab?

I'm trying to use scatter3 to plot n points with color encoded in Matlab. Each point has four parameters, x, y, z, intensity. Now I want to build a 2-dimensional color map which determines the color of each point by two parameters separately, z, and intensity. How should I make it?

Plotting one point in 3D matrix for all slices in 2D plane

I have 3D matrix (100*50*10) and I want to plot one specific point in all slices. Let us say point (10*6*:). The plot should be in 2D plane
Example (I have this coordinate for point that I want to plot)
x (10*6*1)
x (10*6*2)
x (10*6*3)
x (10*6*4)
x (10*6*5)
x (10*6*6)
x (10*6*7)
x (10*6*8)
x (10*6*9)
x (10*6*10)
I tried plot (x(10,6,:)) but I got error
plot(squeeze(x(10,6,:)))
see: https://www.mathworks.com/help/matlab/ref/squeeze.html
x(10,6,:) is still a 3D matrix, and needs to be reduced to a 1D form before plotting it. This is where the squeeze function comes in.

Create depth map from 3d points

I have given 3d points of a scene or a subset of these points comprising one object of the scene. I would like to create a depth image from these points, that is the pixel value in the image encodes the distance of the corresponding 3d point to the camera.
I have found the following similar question
http://www.mathworks.in/matlabcentral/newsreader/view_thread/319097
however the answers there do not help me, since I want to use MATLAB. To get the image values is not difficult (e.g. simply compute the distance of each 3d point to the camera's origin), however I do not know how to figure out the corresponding locations in the 2d image.
I could only imagine that you project all 3d points on a plane and bin their positions on the plane in discrete, well, rectangles on the plane. Then you could average the depth value for each bin.
I could however imagine that the result of such a procedure would be a very pixelated image, not being very smooth.
How would you go about this problem?
Assuming you've corrected for camera tilt (a simple matrix multiplication if you know the angle), you can probably just follow this example
X = data(:,1);
Y = data(:,1);
Z = data(:,1);
%// This bit requires you to make some choices like the start X and Z, end X and Z and resolution (X and Z) of your desired depth map
[Xi, Zi] = meshgrid(X_start:X_res:X_end, Z_start:Z_res:Z_end);
depth_map = griddata(X,Z,Y,Xi,Zi)