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: