How to plot a surface given a vector with data?
Mostrar comentarios más antiguos
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?
Respuestas (1)
Aurele Turnes
el 4 de Ag. de 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
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!