How to use data to plot a 2D image
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!