How to use data to plot a 2D image

2 visualizaciones (últimos 30 días)
afrya
afrya el 10 de Feb. de 2014
Comentada: afrya el 10 de Feb. de 2014
Hello,
I have a dataset with 3 vectors X, Y, and Z and I want to plot a 2D image from this dataset. I don't know how to define X, Y and Z and the color represent by different Z. Do you have any idea how to do this task?
Thanks in advance
  3 comentarios
Walter Roberson
Walter Roberson el 10 de Feb. de 2014
Is your data scattered, at locations indicated by X and Y ?
afrya
afrya el 10 de Feb. de 2014
I want to plot an image with Y vs X and Z Mischa Kim..... My data is not scattered for X and Y

Iniciar sesión para comentar.

Respuestas (1)

arich82
arich82 el 10 de Feb. de 2014
I think this is an oft-requested feature that, to the best of my knowledge, still isn't available in Matlab. The workaround I use is to fake a 2-D line object by taking the overhead view of a very thin 3-D patch, since the surf command automagically colors the object using the Z data (and the plot commands seemingly can only create uniformly-colored objects).
See if this example does what you want:
% dummy data for spiral
n = 5;
theta = [0:0.1:n*360]*pi/180;
r = theta;
x = r.*cos(theta);
y = r.*sin(theta);
z = theta;
% 2-D & 3-D line object
% can only be solid color [as far as I know...]
figure;
plot(x, y);
figure;
plot3(x, y, z);
% make data for *very* thin patch object
tiny = eps(x(:));
X = [x(:), x(:) + tiny];
Y = [y(:), y(:)];
Z = [z(:), z(:)];
% plot using surf, such that Z is used as color data
% (looks black because of EdgeColor)
figure;
surf(X, Y, Z)
% make EdgeColor same as face color,
% then use overhead view so it looks like 2D plot
figure;
surf(X, Y, Z, 'EdgeColor', 'interp')
view(2)
Let me know if this is essentially the plot you wanted, and if this workaround suffices for you application. (You might also check the file exchange for functions which do this; a quick search seems like colormapline might be a candidate http://www.mathworks.com/matlabcentral/fileexchange/39972-colormapline-color-changing-2d-or-3d-line.)
--Andy

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by