To get a surf plot

2 views (last 30 days)
learner
learner on 16 Jul 2015
Commented: Brendan Hamm on 17 Jul 2015
I am a newbie, please also tell how to get a 'surf plot'. I am using MATLAB 2013, plots are shown inactive with the comment 'no variable selected'.

Accepted Answer

Walter Roberson
Walter Roberson on 16 Jul 2015
Example:
data = rand(40,60);
surf(data)
  4 Comments
Walter Roberson
Walter Roberson on 16 Jul 2015
surface plots can only be created for 2 dimension arrays of data. The coordinates can represent a rectangular grid or they can represent 2D parametric coordinates, but either way a surface can only be generated for a triple of data, (x,y,z) .
When you have a surface of n variables, then you have n input values and 1 result value, and you need an (n+1) dimensional output.
MATLAB only has plotting routines up to 3 dimensions -- so 2 input coordinates plus one result.
If you have more input coordinates then you can encode one coordinate as color using the C parameter of surf()
surf(X, Y, Z, C)
It is common to be able to create a "reasonable" surface of 3 inputs and one result (n = 3) this way.
To go beyond to n = 4 or more, you need to find ways to encode the extra dimensions. That can get difficult.
If you use scatter3() then you can encode one dimension as marker size, S
scatter3(X, Y, Z, S, C)
You can also encode information in the marker shape, but you need one plotting call for each different marker shape and there are only a small number of different marker shapes. Marker shapes also do not have any natural ordering, so it is difficult to convey distance using shape.
Information can also be encoded in transparency (Alpha) but it can be difficult to interpret.
The practical maximum is 4 inputs and one outputs, using scatter3 with X, Y, Z and marker size as inputs, and using color for the output. This will not look much like a surface, though. For surfaces, you might end up using X, Y and color for inputs and using Z for the output; I don't know how well that might work. X, Y, Z as inputs and colour for the output is common for drawing things like maps on a sphere and can be effective, but it would not typically be considered a surface plot.
The MATLAB plot routines will automatically determine the coordinate range for label purposes according to the data you plot.
Brendan Hamm
Brendan Hamm on 17 Jul 2015
Just to follow up on this point, there is a function glyphplot in the Statistics and Machine Learning Toolbox which allows for the visualization of up to 17-dimensions. However, this will most certainly not be a surface.

Sign in to comment.

More Answers (1)

Ellison Castro
Ellison Castro on 16 Jul 2015
The 'surf' function is plotting function; it plots your data onto a graph. You should a set of data to be plotted.
  1 Comment
learner
learner on 16 Jul 2015
Thanks Ellison, Sorry for stupid question but please tell me how to set data.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!