How to plot a surface given a vector with data?
1 view (last 30 days)
Show older comments
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
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?
Answers (1)
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.
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
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!