How to plot ellipse using contour function?
19 次查看(过去 30 天)
显示 更早的评论
i would like to plot ellipse using contour function, since it is easier to label curves or lines than plot function , but it does not show the expected lines, the lines should be narrowed towards left and not towards right
%If_dmax is an array (1*201)
%[X,Y] = meshgrid(linspace(-1000,1000,201),linspace(-1000,1000,201));
for k1 = 1:(length(If_dmax))
[C,fContour] = contour(X,Y,sqrt((L_d.*X+L_df*If_dmax(k1)).^2+(L_q.*Y).^2),'ShowText','on', 'LineWidth', 0.5,'EdgeColor',[0 0 1]);
%fContour.LevelStep=0.05;
end
回答(1 个)
John D'Errico
2023-3-13
编辑:John D'Errico
2023-3-13
I'm a little confused. You DID draw ellipses. It seems the goal was not to draw the ellipses you drew though. Essentially, as you did it, you drew ellipses of the form:
(x/a)^2 + (y/b)^2 = R
where R varies, but a was fixed. That is how contour would work, and you were triyng to use contour to solve your prolem. I imagine you saw someone using contour to draw ellipses online somewhere. It may even have been me who showed that trick.
But from your comment, you seem to be asking how to draw ellipses where a varies in the espression
(x/a)^2 + (y/b)^2 = 1
Essentially, that will cause each ellipse to be wider or narrower in the x-direction. Possibly then, a better method is to just use polar coordinates. For example, I'll choose to vary a in that expression, where b is fixed at 1.
b = 1;
theta = linspace(0,2*pi)';
a = 0.25:0.25:2;
x = zeros(size(theta))*a;
% note that I could have done this without using a loop at all, but that
% may have been too much to understand how it works.
for i = 1:numel(a)
x(:,i) = a(i)*cos(theta);
y(:,i) = b*sin(theta);
end
plot(x,y)
legend(string(a))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!