How to use data to plot a 2D image
Mostrar comentarios más antiguos
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
Mischa Kim
el 10 de Feb. de 2014
Do you want to plot X vs. Y and X vs. Z, all in the same plot?
Walter Roberson
el 10 de Feb. de 2014
Is your data scattered, at locations indicated by X and Y ?
afrya
el 10 de Feb. de 2014
Respuestas (1)
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 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!