I need to plot a 3D figure with each data point colored with the value of a 4th variable using a colormap. Lets say I have 4 variables X,Y,Z and W where W = f(X,Y,Z). I want a 3D plot with X, Y, and Z as the three axis. The statement scatter3(X,Y,Z,'filled','b')
gives me a scatter plot in 3D but I want to incorporate the value of Z in the graph by representing the points as an extra parameter (either with different areas :bigger circles for data points with high value of Z and small circles for data points with low value of Z or by plotting the data points with different colors using a colormap). However, I am a novice in MATLAB and dont really know how to proceed. Any help will be highly appreciated.
Thanks in advance!
You are already nearly there... simply use
where s is the point size (scalar, e.g. 3) and W is a vector with your W values. You might also want to issue an
where gcf gets your current figure you are plotting in to significantly increase responsiveness when scattering a lot of data.
So just use
z
for the size vector (4th input) as well as the color vector (5th input):The size vector needs to be greater 0, so you may need to adjust your
z
accordingly.