本文介绍了在MATLAB中绘制椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
具有以下样式的椭圆的参数方程式:
For the parametric equation of an ellipse, which owns the following style:
或者可以写成矩阵形式
现在我想用MATLAB中的系数矩阵[a b c; d e f]
绘制它
Now I want to draw it by the coefficient matrix [a b c; d e f]
in MATLAB
方法1 :plot
function drawEllipse1(mat)
t = linspace(0,2*pi,101);
vec = [sin(t); cos(t); ones(1,length(t))];
%calculate the coordinates of ellipse
ellipse = mat1*vec;
ellipseX = ellipse(1,:);
ellipseY = ellipse(2,:);
plot(ellipseX,ellipseY)
end
方法2 :ezplot
function drawEllipse2(mat)
syms t;
ellipseExpr = mat*[sin(t); cos(t); 1];
%pass a function handle
ezplot(@(t)ellipseExpr(1),@(t)ellipseExpr(2),[0,2*pi])
end
但是,drawEllipse2()
无法正常绘制椭圆吗?我不知道为什么.
However, drawEllipse2()
cannot draw a ellipse normally? I didn't know why.
mat = [1 2 3;4 5 6];
drawEllipse2(mat)
推荐答案
我不确定,但是我认为这是因为您如何传递该函数句柄.如果您只是想做:
I'm not completely sure, but i think its because how you are passing that function handle.If you were to simply do:
ezplot(ellipseExpr(1),ellipseExpr(2),[0,2*pi])
您得到相同的椭圆.
you get the same ellipse.
这篇关于在MATLAB中绘制椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!