Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to rotate a 2D plot around an axis to create a 3D plot?

Subject: How to rotate a 2D plot around an axis to create a 3D plot?

From: Anthony

Date: 17 Apr, 2013 00:49:08

Message: 1 of 2

Let's say I have a simple gaussian defined by:

x=-1:.01:1;
y=exp(-10*(x-.5).^2);

Is there a simple way to create, from this, the plot that would result by rotating this around x=0? It would be a 3D plot that looks like a donut.

Thanks for the help!

Subject: How to rotate a 2D plot around an axis to create a 3D plot?

From: Yehonatan

Date: 21 Apr, 2013 20:19:12

Message: 2 of 2

Hi anthony,
Download gridfit from the matlab exchange and use this code:


clear

x = linspace(-3,3,100);
y = linspace(-3,3,100);
g = 1 - exp(-(x.^2));

f = 1 - exp(-(x.^2));
X = x;
Y(1,1:100) = x(1,50);
X(1,101:200) = x(1,50);
Y(1,101:200) = x;
Z(1,1:100) = f
Z(1,101:200) = f

for ind = 1:100
     X(1,(200 + ind)) = x(1,ind);
     Y(1,(200 + ind)) = x(1,ind);
     
end

Z(1,201:300) = f;

ind = 1;
indx = 1;
indy = 100;

while(ind <= 100)
    X(1,(300 + ind)) = x(1,indx);
    Y(1,(300 + ind)) = y(1,indy);
   
    
    ind = ind + 1;
    indx = indx + 1;
    indy = indy - 1;
end
 
Z(1,301:400) = f;

X = X';
Y = Y';
Z = Z';
figure

zgrid = gridfit(X,Y,Z,x,x);

surf(x,x,zgrid);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us