plot custom cubes inside a sphere

조회 수: 2 (최근 30일)
Ali Farzanehpoor Alwars
Ali Farzanehpoor Alwars 2021년 6월 22일
답변: Mann Baidi 2024년 4월 12일
Hello everyone,
I want to fill a sphere with custom cubes, like this:
This is a 2D illustration, however i want to plot it 3D and after that, consider a specific color for each cube.
Thanks in advance,
A.

답변 (1개)

Mann Baidi
Mann Baidi 2024년 4월 12일
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:
Hope this will help you with your query!

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by