I'm trying to plot a few concentric circles with the following codes, but what I get is an ellipse, i don't know why:
[x,y] = meshgrid(-3:0.1:3,-3:0.1:3);
z = x.^2+y.^2;
contour(x,y,z)

 채택된 답변

Star Strider
Star Strider 2020년 10월 26일

0 개 추천

Use the axis function, specifically either:
axis('equal') % Function Expression
or:
axis equal % Command Expression
.

댓글 수: 5

Randy Chen
Randy Chen 2020년 10월 26일
thanks!
Randy Chen
Randy Chen 2020년 10월 26일
by the way how can I add some radial lines perpendicular to the circles?
That will be diffiicult in contour, although relatively straightforward with plot:
[x,y] = meshgrid(-3:0.1:3,-3:0.1:3);
z = x.^2+y.^2;
[cm,ch] = contour(x,y,z);
hold on
axis('equal')
Lvls = ch.LevelList;
LvlIdx = find(ismember(cm(1,:),Lvls));
LvlNrs = cm(2,LvlIdx);
centre = [mean(cm(1,2:LvlNrs(1))); mean(cm(2,2:LvlNrs(1)))];
angls = linspace(0, 2*pi, 33);
XL = get(gca,'XLim');
YL = get(gca,'Ylim');
plot([centre(1);max(XL(:))]*cos(angls), [centre(2);max(YL(:))]*sin(angls), '-g')
Experiment to get the result you want.
Randy Chen
Randy Chen 2020년 10월 27일
thanks a lot!
Star Strider
Star Strider 2020년 10월 27일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

질문:

2020년 10월 26일

댓글:

2020년 10월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by