Question surf() fuction
1 回表示 (過去 30 日間)
古いコメントを表示
I am generationg a revolution solid of a gaussian fuction and when I use the surf() fuction I get the graphic that I need, but I have to get this figure in a matrix NxN with each element of this matrix be a gray value (it will be my height) but I don´t know how do it!
Can you help me?
This is my code:
r = x(1:1024); %0:0.1:30; x(513:1024)
z = gaussmf(r,[13.32 0]);%exp(-r.^2/(2*(13.32).^2));
theta = 0:pi/20:2*pi;
xx = bsxfun(@times,r',cos(theta));
yy = bsxfun(@times,r',sin(theta));
zz = repmat(z',1,length(theta));
figure()
surf(xx,yy,zz)
axis equal
0 件のコメント
回答 (1 件)
AR
2025 年 3 月 27 日
As per my understanding, you want to convert the 3D surface plot into a 2D NxN matrix where each element represents a grayscale value corresponding to the height of the surface.
To do this conversion, you can follow the below steps:
1. Set the resolution for the output Matrix - size N
N = 1024; % Define the resolution of the output matrix
2. Use “meshgrid” to create a grid (xq,yq) which will represent the NxN matrix.
[xq, yq] = meshgrid(linspace(min(xx(:)), max(xx(:)), N), linspace(min(yy(:)), max(yy(:)), N));
3. Use “griddata” to interpolate zz onto 2D grid (xq,yq).
zq = griddata(xx, yy, zz, xq, yq);
4. Normalize the heights to fit into the grayscale image.
zq_normalized = uint8(255 * mat2gray(zq));
5. Display the 2D matrix as a grayscale image.
figure();
imshow(zq_normalized, []);
title('Grayscale Matrix of Revolution Solid');
You can refer the below MathWorks Documentations for more information:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!