Surf to image conversion

Hi all, I have the following code:
h = getHeight;
x = getX;
y = getY;
z = getZ;
D=500;
height = z + h;
surf(x,y,height);
This generates a sphere (diameter 500) with a 3-dimensional etching with z-component "h" (h = getHeight; calls the global h variable.) This z-component "h" is very very small compared to the rest of the sphere. I want to make it such that when I use the image() function that I am given a 2-dimensional image of this etching that plots h(x,y) where every point on my 2-dimensional image shows an h value. I have attached a picture of what the surf looks like. You can see that the etching is very very small but actually does have thickness. Any suggestions?

1 件のコメント

madhan ravi
madhan ravi 2018 年 12 月 25 日
saveas() ?

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

回答 (2 件)

Image Analyst
Image Analyst 2018 年 12 月 25 日

0 投票

No, that code you posted doesn't make that, and in fact doesn't even run - you must have left something out.
Anyway, use the 'EdgeColor', 'none' option. For example:
[X,Y] = meshgrid(-5:.5:5);
Z = Y.*sin(X) - X.*cos(Y);
s = surf(X,Y,Z,'FaceAlpha',0.85, 'EdgeColor', 'none')
Walter Roberson
Walter Roberson 2018 年 12 月 25 日

0 投票

N = 500;
xmin = min(x); xmax = max(x);
ymin = min(y); ymax = max(y);
xidx = 1 + floor((x - xmin) ./ (xmax - xmin) * (N-1));
yidx = 1 + floor((y - ymin) ./ (ymax - ymin) * (N-1));
gridded_height = accumarray( [yidx(:), xidx(:)], height(:), [N N], @max, nan);
image(gridded_height, 'Xdata', [xmin, xmax], 'Ydata', [ymin ymax])

4 件のコメント

Harrison Chong
Harrison Chong 2018 年 12 月 25 日
Hi, I get this error when I run your code:
Error using accumarray
First input SUBS must contain positive integer subscripts.
Error in run2 (line 27)
gridded_height = accumarray( [yidx(:), xidx(:)], height(:), [N N], @max, nan);
Image Analyst
Image Analyst 2018 年 12 月 25 日
What are you using for x and y? Attach your script.
Walter Roberson
Walter Roberson 2018 年 12 月 25 日
Is it possible that x or y are constant? The code expects min(x) to be different than max(x) and min(y) to be different than max(y)
Harrison Chong
Harrison Chong 2018 年 12 月 28 日
x and y are not constant.

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

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

2018 年 12 月 25 日

コメント済み:

2018 年 12 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by