use surf() to plot a circle from a rectangle matrix

17 ビュー (過去 30 日間)
Marvin Lochmann
Marvin Lochmann 2019 年 1 月 4 日
回答済み: Image Analyst 2019 年 1 月 4 日
Hey everybody,
I have a greyscale picture and i want to surface plot just a circle from it.
I tried to cut out the circle and plot it with surf(). It didnt work.
After that, i tried to assign NaN to the values i dont want to plot. But they are plotted as zeros. I didnt find a way to ignore those values.
i attached the picture file i am using.
What am i doing wrong?
Im a real Matlab beginner by the way.
Scan_rec0254.bmp

回答 (2 件)

Cris LaPierre
Cris LaPierre 2019 年 1 月 4 日
Sure. See this StackExchange post about exactly this. I'm copying the code below
[x, y] = ndgrid(linspace(-1,1,500));
z = cos(2*pi*(x+y)*2);
z(x.^2+y.^2>1) = NaN; %// remove values outside unit circle
surf(x,y,z,'edgecolor','none')
colorbar
view(2)
axis equal
view(2) creates a top down view.
bdYRD.png
view(3) creates a 3d view
surfCircle.png

Image Analyst
Image Analyst 2019 年 1 月 4 日

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by