How to use data to plot a 2D image

조회 수: 1 (최근 30일)
afrya
afrya 2014년 2월 10일
댓글: afrya 2014년 2월 10일
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
Walter Roberson
Walter Roberson 2014년 2월 10일
Is your data scattered, at locations indicated by X and Y ?
afrya
afrya 2014년 2월 10일
I want to plot an image with Y vs X and Z Mischa Kim..... My data is not scattered for X and Y

댓글을 달려면 로그인하십시오.

답변 (1개)

arich82
arich82 2014년 2월 10일
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

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by