How to plot an elliptical surface in Matlab?

Hello there,
Is there a way to plot an elliptical surface (elliptical plate) in Matlab? I've tried the code below (among other codes), but instead of an ellipse, I get a squared shape (I think it is because of meshgrid).
a= 8; b = 6; x=linspace(-a,a,60); y = b*sqrt(1-(x./a).^2);
x = [x; x(length(x):-1:1)]; y = [-y, y];
[x,y]=meshgrid(x,y);
%y = b*sqrt(1-(x./a).^2);
z = ones(size(x));
surface(x,y,z)
Thank you,

回答 (4 件)

Joseph Cheng
Joseph Cheng 2014 年 4 月 22 日
編集済み: Joseph Cheng 2014 年 4 月 22 日

0 投票

depending on what you want to do with it matlab has the function
[x, y, z] = ellipsoid(0,0,0,8,6,3.25,30);
you'll only need half of the generated ellipsoid and you can flatten z to be 1.
Andrew Newell
Andrew Newell 2014 年 4 月 22 日
編集済み: Andrew Newell 2014 年 4 月 22 日

0 投票

You have defined the perimeter of an ellipse, and meshgrid just turns it into a square grid. The command patch allows you to plot your ellipse and fill it with your color of choice.
a= 8; b = 6; x=linspace(-a,a,60); y = b*sqrt(1-(x./a).^2);
x = [x fliplr(x)]; y = [-y y]; z = ones(size(x));
patch(x,y,z,'g')
axis equal
The command axis equal ensures that the ellipse has its true shape and is not distorted by the scale.
Here is another example where z varies and the view is specified:
a= 8; b = 6; x=linspace(-a,a,60); y = b*sqrt(1-(x./a).^2);
x = [x fliplr(x)]; y = [-y y]; z = sin(x);
patch(x,y,z,'g')
axis equal
view(18,22)
fernanr5
fernanr5 2014 年 4 月 22 日

0 投票

Thank you for your response. The problem is that z is actually a function of x and/or y. So say z=sin(x). In the code I set z = 1 just as an example, but I really want it to vary with x and y.
Appreciate your help.
fernanr5
fernanr5 2014 年 4 月 22 日

0 投票

Thanks for your response. However, I am looking for a 3D plot (surface plot).
Thank you,

1 件のコメント

Andrew Newell
Andrew Newell 2014 年 4 月 22 日
It is 3D. You can rotate the axes using the rotate tool in the plot window or using view.
Please note that it is less confusing to use "Comment on this Answer" to respond to a particular answer.

サインインしてコメントする。

カテゴリ

質問済み:

2014 年 4 月 22 日

編集済み:

2014 年 4 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by