Plot 3d graphs of a 2D gaussian function

13 views (last 30 days)
Hello, I have two gaussian variables and their probabilities.
The number of points is limited to 200 and I want to plot the probability on a 3D graph but I cannot succeed in get what I want. I have followed http://www.mathworks.com/matlabcentral/answers/220-3d-plot-from-imported-excel-data which is great but my output do not work. I wanted to have something with surf like http://upload.wikimedia.org/wikipedia/commons/c/ce/Gaussian_2d.png.
I attach my txt file content, if someone can give a suggestion or an idea how to solve it. Take into account that 1/4 of the gaussian is cut because of unphysical condition in that area.
81240.1600000000 67443 1.96409000000000e-05
85302.1680000000 67443 9.92480000000000e-05
89364.1760000000 67443 0.000349893000000000
93426.1840000000 67443 0.000860601000000000
97488.1920000000 67443 0.00147680000000000
101550.200000000 67443 0.00176805200000000
105612.208000000 67443 0.00147680000000000
109674.216000000 67443 0.000860601000000000
113736.224000000 67443 0.000349893000000000
117798.232000000 67443 9.92480000000000e-05
121860.240000000 67443 1.96409000000000e-05
81240.1600000000 70815.1500000000 9.92474000000000e-05
85302.1680000000 70815.1500000000 0.000501509000000000
89364.1760000000 70815.1500000000 0.00176804000000000
93426.1840000000 70815.1500000000 0.00434869300000000
97488.1920000000 70815.1500000000 0.00746240300000000
101550.200000000 70815.1500000000 0.00893412500000000
105612.208000000 70815.1500000000 0.00746240300000000
109674.216000000 70815.1500000000 0.00434869300000000
113736.224000000 70815.1500000000 0.00176804000000000
117798.232000000 70815.1500000000 0.000501509000000000
121860.240000000 70815.1500000000 9.92474000000000e-05
81240.1600000000 74187.3000000000 0.000349889000000000
85302.1680000000 74187.3000000000 0.00176803200000000
89364.1760000000 74187.3000000000 0.00623308800000000
93426.1840000000 74187.3000000000 0.0153309760000000
97488.1920000000 74187.3000000000 0.0263081160000000
101550.200000000 74187.3000000000 0.0314965560000000
105612.208000000 74187.3000000000 0.0263081160000000
109674.216000000 74187.3000000000 0.0153309760000000
113736.224000000 74187.3000000000 0.00623308800000000
117798.232000000 74187.3000000000 0.00176803200000000
121860.240000000 74187.3000000000 0.000349889000000000
81240.1600000000 77559.4500000000 0.000860588000000000
85302.1680000000 77559.4500000000 0.00434865600000000
89364.1760000000 77559.4500000000 0.0153309220000000
93426.1840000000 77559.4500000000 0.0377081170000000
97488.1920000000 77559.4500000000 0.0647075250000000
101550.200000000 77559.4500000000 0.0774690280000000
105612.208000000 77559.4500000000 0.0647075250000000
109674.216000000 77559.4500000000 0.0377081170000000
113736.224000000 77559.4500000000 0.0153309220000000
117798.232000000 77559.4500000000 0.00434865600000000
121860.240000000 77559.4500000000 0.000860588000000000
81240.1600000000 80931.6000000000 0.00147677500000000
85302.1680000000 80931.6000000000 0.00746232400000000
89364.1760000000 80931.6000000000 0.0263079670000000
93426.1840000000 80931.6000000000 0.0647073880000000
97488.1920000000 80931.6000000000 0.111038557000000
101550.200000000 80931.6000000000 0.132937383000000
105612.208000000 80931.6000000000 0.111038557000000
109674.216000000 80931.6000000000 0.0647073880000000
113736.224000000 80931.6000000000 0.0263079670000000
117798.232000000 80931.6000000000 0.00746232400000000
121860.240000000 80931.6000000000 0.00147677500000000
85302.1680000000 84303.7500000000 0.00893402400000000
89364.1760000000 84303.7500000000 0.0314963550000000
93426.1840000000 84303.7500000000 0.0774688080000000
97488.1920000000 84303.7500000000 0.132937289000000
101550.200000000 84303.7500000000 0.159154943000000
105612.208000000 84303.7500000000 0.132937289000000
109674.216000000 84303.7500000000 0.0774688080000000
113736.224000000 84303.7500000000 0.0314963550000000
117798.232000000 84303.7500000000 0.00893402400000000
121860.240000000 84303.7500000000 0.00176802000000000
89364.1760000000 87675.9000000000 0.0263079670000000
93426.1840000000 87675.9000000000 0.0647073880000000
97488.1920000000 87675.9000000000 0.111038557000000
101550.200000000 87675.9000000000 0.132937383000000
105612.208000000 87675.9000000000 0.111038557000000
109674.216000000 87675.9000000000 0.0647073880000000
113736.224000000 87675.9000000000 0.0263079670000000
117798.232000000 87675.9000000000 0.00746232400000000
121860.240000000 87675.9000000000 0.00147677500000000
93426.1840000000 91048.0500000000 0.0377081170000000
97488.1920000000 91048.0500000000 0.0647075250000000
101550.200000000 91048.0500000000 0.0774690280000000
105612.208000000 91048.0500000000 0.0647075250000000
109674.216000000 91048.0500000000 0.0377081170000000
113736.224000000 91048.0500000000 0.0153309220000000
117798.232000000 91048.0500000000 0.00434865600000000
121860.240000000 91048.0500000000 0.000860588000000000
97488.1920000000 94420.2000000000 0.0263081160000000
101550.200000000 94420.2000000000 0.0314965560000000
105612.208000000 94420.2000000000 0.0263081160000000
109674.216000000 94420.2000000000 0.0153309760000000
113736.224000000 94420.2000000000 0.00623308800000000
117798.232000000 94420.2000000000 0.00176803200000000
121860.240000000 94420.2000000000 0.000349889000000000
101550.200000000 97792.3500000000 0.00893412500000000
105612.208000000 97792.3500000000 0.00746240300000000
109674.216000000 97792.3500000000 0.00434869300000000
113736.224000000 97792.3500000000 0.00176804000000000
117798.232000000 97792.3500000000 0.000501509000000000
121860.240000000 97792.3500000000 9.92474000000000e-05
101550.200000000 101164.500000000 0.00176805200000000
105612.208000000 101164.500000000 0.00147680000000000
109674.216000000 101164.500000000 0.000860601000000000
113736.224000000 101164.500000000 0.000349893000000000
117798.232000000 101164.500000000 9.92480000000000e-05
121860.240000000 101164.500000000 1.96409000000000e-05
82864.8000000000 68791.8400000000 7.82526000000000e-05
87008.0400000000 68791.8400000000 0.000351359000000000
91151.2800000000 68791.8400000000 0.00108477800000000
95294.5200000000 68791.8400000000 0.00230286300000000
99437.7600000000 68791.8400000000 0.00336150000000000
103581 68791.8400000000 0.00337392700000000
107724.240000000 68791.8400000000 0.00232849800000000
111867.480000000 68791.8400000000 0.00110497800000000
116010.720000000 68791.8400000000 0.000360553000000000
120153.960000000 68791.8400000000 8.08951000000000e-05
124297.200000000 68791.8400000000 1.24799000000000e-05
82864.8000000000 72231.4320000000 0.000351353000000000
87008.0400000000 72231.4320000000 0.00157759700000000
91151.2800000000 72231.4320000000 0.00487063700000000
95294.5200000000 72231.4320000000 0.0103398240000000
99437.7600000000 72231.4320000000 0.0150930890000000
103581 72231.4320000000 0.0151488870000000
107724.240000000 72231.4320000000 0.0104549250000000
111867.480000000 72231.4320000000 0.00496133700000000
116010.720000000 72231.4320000000 0.00161887800000000
120153.960000000 72231.4320000000 0.000363218000000000
124297.200000000 72231.4320000000 5.60348000000000e-05
82864.8000000000 75671.0240000000 0.00108474300000000
87008.0400000000 75671.0240000000 0.00487055900000000
91151.2800000000 75671.0240000000 0.0150372560000000
95294.5200000000 75671.0240000000 0.0319224300000000
99437.7600000000 75671.0240000000 0.0465973180000000
103581 75671.0240000000 0.0467695830000000
107724.240000000 75671.0240000000 0.0322777820000000
111867.480000000 75671.0240000000 0.0153172740000000
116010.720000000 75671.0240000000 0.00499800700000000
120153.960000000 75671.0240000000 0.00112137200000000
124297.200000000 75671.0240000000 0.000172998000000000
82864.8000000000 79110.6160000000 0.00230275200000000
87008.0400000000 79110.6160000000 0.0103394940000000
91151.2800000000 79110.6160000000 0.0319219240000000
95294.5200000000 79110.6160000000 0.0677667140000000
99437.7600000000 79110.6160000000 0.0989193840000000
103581 79110.6160000000 0.0992850790000000
107724.240000000 79110.6160000000 0.0685210760000000
111867.480000000 79110.6160000000 0.0325163630000000
116010.720000000 79110.6160000000 0.0106100490000000
120153.960000000 79110.6160000000 0.00238051200000000
124297.200000000 79110.6160000000 0.000367249000000000
82864.8000000000 82550.2080000000 0.00336128500000000
87008.0400000000 82550.2080000000 0.0150923720000000
91151.2800000000 82550.2080000000 0.0465958510000000
95294.5200000000 82550.2080000000 0.0989178380000000
99437.7600000000 82550.2080000000 0.144390822000000
103581 82550.2080000000 0.144924620000000
107724.240000000 82550.2080000000 0.100018965000000
111867.480000000 82550.2080000000 0.0474635430000000
116010.720000000 82550.2080000000 0.0154872950000000
120153.960000000 82550.2080000000 0.00347479000000000
124297.200000000 82550.2080000000 0.000536067000000000
87008.0400000000 85989.8000000000 0.0151479330000000
91151.2800000000 85989.8000000000 0.0467673900000000
95294.5200000000 85989.8000000000 0.0992819960000000
99437.7600000000 85989.8000000000 0.144922386000000
103581 85989.8000000000 0.145458149000000
107724.240000000 85989.8000000000 0.100387178000000
111867.480000000 85989.8000000000 0.0476382770000000
116010.720000000 85989.8000000000 0.0155443100000000
120153.960000000 85989.8000000000 0.00348758200000000
124297.200000000 85989.8000000000 0.000538041000000000
91151.2800000000 89429.3920000000 0.0322757780000000
95294.5200000000 89429.3920000000 0.0685179070000000
99437.7600000000 89429.3920000000 0.100015904000000
103581 89429.3920000000 0.100385653000000
107724.240000000 89429.3920000000 0.0692806310000000
111867.480000000 89429.3920000000 0.0328768070000000
116010.720000000 89429.3920000000 0.0107276610000000
120153.960000000 89429.3920000000 0.00240690000000000
124297.200000000 89429.3920000000 0.000371320000000000
95294.5200000000 92868.9840000000 0.0325143730000000
99437.7600000000 92868.9840000000 0.0474613790000000
103581 92868.9840000000 0.0476368390000000
107724.240000000 92868.9840000000 0.0328763150000000
111867.480000000 92868.9840000000 0.0156013050000000
116010.720000000 92868.9840000000 0.00509068600000000
120153.960000000 92868.9840000000 0.00114216600000000
124297.200000000 92868.9840000000 0.000176206000000000
99437.7600000000 96308.5760000000 0.0154863600000000
103581 96308.5760000000 0.0155436110000000
107724.240000000 96308.5760000000 0.0107273420000000
111867.480000000 96308.5760000000 0.00509061100000000
116010.720000000 96308.5760000000 0.00166106000000000
120153.960000000 96308.5760000000 0.000372682000000000
124297.200000000 96308.5760000000 5.74949000000000e-05
103581 99748.1680000000 0.00348737500000000
107724.240000000 99748.1680000000 0.00240679300000000
111867.480000000 99748.1680000000 0.00114213300000000
116010.720000000 99748.1680000000 0.000372677000000000
120153.960000000 99748.1680000000 8.36152000000000e-05
124297.200000000 99748.1680000000 1.28996000000000e-05
103581 103187.760000000 0.000538001000000000
107724.240000000 103187.760000000 0.000371299000000000
111867.480000000 103187.760000000 0.000176198000000000
116010.720000000 103187.760000000 5.74932000000000e-05
120153.960000000 103187.760000000 1.28994000000000e-05
124297.200000000 103187.760000000 1.99003000000000e-06

Accepted Answer

Andrew Newell
Andrew Newell on 17 Jul 2011
If the above data are copied into a file 2dGaussianData.dat, the following code can give you the surface you want:
A = importdata('2dGaussianData.dat');
x = A(:,1); y = A(:,2); z = A(:,3);
Your data are not on a regular grid (although they start out looking like they are), so you need to interpolate:
F = TriScatteredInterp(x,y,z);
Now define the grid for plotting your surface:
qx = linspace(min(x),max(x),100); % define your grid here
qy = linspace(min(y),max(y),100);
[qx,qy] = meshgrid(qx,qy);
Finally, calculate the interpolating surface and plot it.
qz = F(qx,qy);
h = surfc(qx,qy,qz,'LineStyle','none');
If you'd like to see where your data lie on this surface, you can add the following commands:
hold on;
plot3(x,y,z,'k.')
  2 Comments
AYUSH SINGHAL
AYUSH SINGHAL on 14 Mar 2020
i don't have an equation for a 2D curve but have points which i have attached herewith.
now i want to plot this curve in 3D, with similar kind of variation in y axis as well.
can you suggest a way to do this??
Wolfgang
Wolfgang on 15 Sep 2020
F= TriScatteredInterp does not work in my case. the function is known.

Sign in to comment.

More Answers (2)

mortain
mortain on 17 Jul 2011
Thank you very much, it is working in a wonderful manner!
I have understood how it works....

Sumit Kushwaha
Sumit Kushwaha on 29 Jun 2017
I have gray scale noisy image (2-D). I want to plot Gaussian PDF for this 2-D gray scale noisy image in MATLAB. Please help

Products

Community Treasure Hunt

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

Start Hunting!