Hi Ali,
As per my understading of the question,you would like to plot grid/cubes in a 3D sphere in MATLAB.
I would suggest you to use the 'surf' function in MATLAB for the same. You can change the dimensions of the cubes by specifying the number of faces of the sphere.
[X,Y,Z] = sphere(number_of_faces);
For coloring the cubes you can use the colormap function in MATLAB.
You can take help of the following code to proceed further.
[X,Y,Z] = sphere(50);
surf(X,Y,Z)
num_points = numel(Z);
cmap = cool(num_points);
cmap(:,3)=(1:num_points)'/num_points;
hold on;
colorbar
colormap(cmap)
Feel free to explore more about the 'sphere', 'surf' and 'colormap' function using the documentation links mentioned below:
- Sphere: https://www.mathworks.com/help/matlab/ref/sphere.html
- Surf: https://www.mathworks.com/help/matlab/ref/surf.html
- Colormap: https://www.mathworks.com/help/matlab/ref/colormap.html
Hope this will help you with your query!