How to use data to plot a 2D image

2 visualizzazioni (ultimi 30 giorni)
afrya
afrya il 10 Feb 2014
Commentato: afrya il 10 Feb 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 Commenti
Walter Roberson
Walter Roberson il 10 Feb 2014
Is your data scattered, at locations indicated by X and Y ?
afrya
afrya il 10 Feb 2014
I want to plot an image with Y vs X and Z Mischa Kim..... My data is not scattered for X and Y

Accedi per commentare.

Risposte (1)

arich82
arich82 il 10 Feb 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

Categorie

Scopri di più su Lighting, Transparency, and Shading in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by