3D Distribution Plot on Matlab

In summary, the individual is trying to build a Matlab code to create a 3D distribution of a parameter (such as density or temperature) and visualize it as a cone shape. They have attempted a 2D normal distribution but are struggling with applying it to a 3D case. They are asking for assistance and guidance on how to approach this problem.
  • #1
galanos
2
0
Im trying to build a Matlab code for the distribution of a parameter (such as density or temperature) in 3D, then visualise the distribution also in 3D. At the end, the distribution plot should look like a cone shape where the highest value for the density (or temperature) is at the tip of the cone and lower values as moving down and outwards on the cone. So that density should decrease both by horizontal and vertical distance from the cone tip. I've tried Normal (Gausian) distribution for the 2D case and it worked but i don't know how to apply that for 3D case and I am really lost!

What I am intended to do is to use many equally sized cells (cubes) to define a 3D environment (volume) and then assign values for the density to each of these cells according to a distribution function (normal dist func.)

Here is what I've tried so far for the 2D case. You may see several funny mistakes since I am almost a beginner on Matlab! Please give me some idea and light up my world!

% Standard Normal Distribution of Density
clear all,close all
% Parameters:
% x:cell number
% l: total length of cells in a layer
% h: distance from the cone tip
% d_cell: dimension of the cell
% i: layer number
% m: mass in each layer (constant)

theta = pi/10; % cone angle (18 deg)
d_cell = 0.1; % cell dimension
cell_volume = d_cell^3;
mu = 0; % mean value of the normal distribution
m = 0.005; %row mass

symvar h; % symbolic variable
h = 1:60;
l = 2*h*tan(theta/2);
% plot(h,l(h));

% number of cells in each layer:-----------------------------------------
n = l/d_cell;
n = fix((n(h)+1)/2)*2-1; % rounds to the nearest smaller odd number

% standard deviation of the density distribution:------------------------
sigma = [];
sigma(1) = 1;
for j = 2:60
sigma(j) = sigma(j-1)*(n(j)/n(j-1));
end

% normal distribution of density on each layer:--------------------------
x = cell(60,1);
y = cell(60,1);
N = cell(60,1);
coef = cell(60,1);
for i = 1:60
t = (n(i)-1)/2;
x{i,1} = 1:t;
y{i,1} = (exp(-(x{i,1}-mu).^2/(2*(sigma(i)).^2)))./(sigma(i)*sqrt(2*pi));
N{i,1} = y{i,1}/max(y{i,1});
coef{i,1} = m/sum(cell_volume*N{i,1});
N{i,1} = coef{i,1}*N{i,1};
end

plot(x{i,1},N{i,1});

Thanks in advance for any help..
 
Physics news on Phys.org
  • #2


Hello there,

As a fellow scientist, I understand your struggle with trying to code a 3D distribution in Matlab. It can definitely be challenging, but I'm here to help you out!

First of all, for your 3D distribution, you will need to use a 3D grid instead of a 2D grid like you have in your code. This means that instead of having a single layer, you will have multiple layers stacked on top of each other to create a 3D volume.

To create this 3D grid, you will need to define the dimensions of your volume, which can be done using the "meshgrid" function in Matlab. This function will create a grid of points in 3D space, which you can then use to assign your density values to each cell.

Next, you will need to define your cone shape in 3D space. This can be done using the "surf" function in Matlab, which will create a surface plot of your cone. You can then use this surface as a guide to assign your density values to each cell in the 3D grid.

To assign your density values, you can use the same normal distribution function that you used in your 2D code, but this time you will need to use a 3D version of it. This can be done by using the "ndgrid" function in Matlab, which will create a 3D grid of points that you can use as inputs to your normal distribution function.

Once you have assigned density values to each cell in the 3D grid, you can then use the "isosurface" function in Matlab to create a 3D surface plot of your distribution. This will give you the cone shape that you are looking for, with the highest density at the tip of the cone and lower values as you move down and outwards on the cone.

I hope this helps to give you some direction in coding your 3D distribution. If you have any further questions, feel free to reach out and I'll be happy to assist you further. Good luck with your project!
 
  • #3


Dear researcher,

Thank you for sharing your code and your intended goal. It seems like you are on the right track with using a normal distribution to represent the density or temperature in your 3D environment. However, I would suggest a few modifications to your approach.

Firstly, instead of using a cone shape, I would recommend using a spherical shape for your 3D environment. This is because a cone shape may not accurately represent the distribution of density or temperature in all directions. A sphere, on the other hand, can represent a more uniform distribution in all directions.

Secondly, instead of using equally sized cells, I would suggest using a grid of points within the spherical volume to represent the cells. This will allow for a more precise representation of the distribution and will also make it easier to visualize in 3D.

Lastly, instead of using a fixed mass for each layer, I would suggest using a variable mass that is proportional to the volume of each cell. This will ensure that the total mass in the environment remains constant and that the density distribution is accurately represented.

I hope these suggestions help in your coding process. If you need further assistance, I would recommend consulting with a more experienced Matlab user or reaching out to the Matlab community for additional support. Good luck with your project!
 

1. What is a 3D distribution plot on Matlab?

A 3D distribution plot on Matlab is a graphical representation of the distribution of data in a three-dimensional space. It is created using the functions provided in the Matlab software and is useful for visualizing complex data sets and identifying patterns or trends.

2. How do I create a 3D distribution plot on Matlab?

To create a 3D distribution plot on Matlab, you will need to have a set of data points with three variables. Then, you can use the "scatter3" function to plot the points in a 3D space. You can also customize the plot by adding labels, changing color and size of the points, and adjusting the viewing angle.

3. What are some applications of 3D distribution plots on Matlab?

3D distribution plots on Matlab have various applications in scientific research and data analysis. They can be used to visualize the distribution of physical properties such as temperature, pressure, or density in a three-dimensional space. They are also useful for analyzing and comparing complex data sets in fields such as biology, chemistry, and engineering.

4. Can I add multiple data sets to a 3D distribution plot on Matlab?

Yes, you can add multiple data sets to a 3D distribution plot on Matlab by using the "hold on" function. This allows you to plot additional data points on the same graph and compare their distribution with the existing data set. You can also use different colors or markers for each data set to distinguish them.

5. Is it possible to export a 3D distribution plot from Matlab to other software?

Yes, you can export a 3D distribution plot from Matlab to other software such as Microsoft Excel or Adobe Illustrator. This can be done by saving the plot as an image file or by copying and pasting the plot into the desired software. You can also save the plot as a figure file in Matlab and import it into other Matlab scripts for further analysis.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
26K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
742
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
736
Back
Top