Surf plot line by line

2 ビュー (過去 30 日間)
TheStranger
TheStranger 2017 年 8 月 22 日
コメント済み: KSSV 2017 年 8 月 23 日
Hello there!
I want to make a 3D surface plot with, but I have the following problem.
Imagine that I have X and Y vectors and plot some function of them as Z using the colormap. The trick is that my Y-values might depend upon values of the X-vector, meaning that for a fixed xj = X(1, j) I might have different Yj vectors. So, the obvious solution is to plot it line-by-line fixing a particular X-value and plotting the Y dependency of the function. The problem is that surf does not support Z as vectors.
I kind of found the way to do that, but its not exactly what I wanted.
Here comes some code: Conventional 3D SurfPlot of some function:
yvec = linspace(0.0, 2*pi, 100);
xvec = linspace(0.0, 2*pi, 200);
[xm, ym] = meshgrid(xvec, yvec);
zmat = cos(xm).*sin(ym);
figure
surf(xvec, yvec, zmat, 'edgealpha', 0.0); hold on;
xlim([min(xvec), max(xvec)]);
colormap(jet(250));colorbar;
view(0,90);
and then I just make slices of the X vector, but not containing the last possible slice, which would be a single point, making Z not a matrix, but a vector and, therefore, throwing an error.
figure
for ind = length(xvec)-1:-1:1
yvec = linspace(0.0, 2*pi, 100);
yvec = yvec + 0.1*rand(1, 100);
[xm, ym] = meshgrid(xvec(ind:end), yvec);
zmat = cos(xm).*sin(ym);
surf(xvec(1, ind:end), yvec, zmat, 'edgealpha', 0.0); hold on;
xlim([min(xvec), max(xvec)]);
colormap(jet(250));brighten(0.2);colorbar;
view(0,90);
end
As an example I just added some random noise to the y-values, so that it varies for each xvec(1, ind) value.
Is there any other way to do it efficiently? Actually, this looping takes more time to plot and this method also obviously loses one line of data related to xvec(1, end).

回答 (1 件)

KSSV
KSSV 2017 年 8 月 22 日
Doc waterfall
  2 件のコメント
TheStranger
TheStranger 2017 年 8 月 23 日
編集済み: TheStranger 2017 年 8 月 23 日
Yeah, it does not have such a restriction that z mast be a matrix, but it looks a bit awful, if you want to see some colormap, since it does not connect the X/Y lines, so ~half is just an empty space. Compare
I don't see anything about the linewidth for 'waterfall' func.
Anyway, thx
KSSV
KSSV 2017 年 8 月 23 日
What you expect?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by