How to plot a surface given a vector with data?

2 views (last 30 days)
Hi all,
I have a vector of data which correspond to deviations of a base value. Let's say vector D
D= [0 1 5 11 32 4 5 8 0 2 23 0 ...etc]
where 0 means base level. If I plot these data I get something very similar to signal wave (only positive values) without a perfectly constant pattern though. That is only to describe how the data looks like. For this vector D I also have a corresponding matrix of coordinates (extremely low differences with each other though since the data correspond to a small road segment), as well as a vector which shows the distance in meters (D includes data that describe 80m along a road segment).
What I want to create and I fail to, is to plot the surface of these data (as if drawing these road segments where the peaks will be formed with different colours according to their height. I have tried
surf(X,Y,Z)
with the coordinates as X,Y and the D as Z but it does not work. Not even
plot3
is really appropriate for what I want to show.
Any ideas of how to represent it nicely?
  2 Comments
José-Luis
José-Luis on 14 Jul 2014
Does not work is not a very descriptive statement of your problem for those attempting to help you? What's the error message? What did you expect to get and what did you get instead?
Iro
Iro on 14 Jul 2014
Thanks Jose Luis,
You are right,
the error message is that z should be a matrix and not a vector or scalar.
I am basically looking for ideas of how to get something illustrative, like the representation of these kind of peaks in a 3D level, with the data I mentioned that I have.
Iro

Sign in to comment.

Answers (1)

Aurele Turnes
Aurele Turnes on 4 Aug 2014
The error you get comes from the fact that the Z input to the surf function must be a matrix.
It seems like you want the peaks of the (x,y,D) data to have different colors according to their height.
To do this, you could use the scatter3 function ( see documentation ) as follows
scatter3(x,y,D,10,D,'fill');
You can also try using stem3 ( see documentation ) and include the color information by creating a colormap scaled based on the D values. For instance, using random data you would do:
x = sort(randn(10,1));
y = sort(randn(10,1));
D = randn(10,1);
figure;
hold on;
cm = colormap;
colorindex = 1+round( ( (D - min(D))*(length(cm)-1) )./(max(D)-min(D)) );
for i=1:numel(x)
sth = stem3(x(i),y(i),D(i), 'color', cm(colorindex(i),:));
end

Community Treasure Hunt

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

Start Hunting!