Hello guys, I want to plot every point (x element of [-4,4], y element of [-4,4]) that meets the following conditions:
  • norm([x;y])<=4
The syntax is not right here, but I hope you understand what I'm looking for. For example the point x = 2, y = 2 would meet my requirements and therefore should be plotted.
I am aware of the fact that this is just another way of drawing a circle, but I want to dynamically change my norm (i.e. norm([x;y],1)). I am thankful for every bit of help I can get.

댓글 수: 2

Have you taken a look at meshgrid?
[X,Y]=meshgrid(-4:4,-4:4);
D=sqrt(X.^2+Y.^2);
DerMischa
DerMischa 2017년 11월 25일
I know meshgrid but how do I plot my circle now ?

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

 채택된 답변

Rik
Rik 2017년 11월 26일

0 개 추천

If you are not actually after plotting point, you can use fill.
radius=4;
theta=linspace(0,2*pi,200);
x=radius*cos(theta);
y=radius*sin(theta);
fill(x,y,'r')
axis([-radius radius -radius radius])
daspect([1 1 1])
If you want to plot the points:
radius=4;
[X,Y]=meshgrid(-radius:0.1:radius);
D=(X.^2+Y.^2);
plot(X(D<=radius^2),Y(D<=radius^2),'.')
axis([-radius radius -radius radius])
daspect([1 1 1])

댓글 수: 1

DerMischa
DerMischa 2017년 11월 26일
Thank you this is almost perfect, and will do the job just fine.

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

추가 답변 (1개)

Jan
Jan 2017년 11월 25일

0 개 추천

Since Matlab R2016 with auto expanding:
x = -4:4;
x2 = x.^2;
D = x2 .* x2.' < 16;
Note: Comparing with 4^2 is cheaper than calculating the SQRT().

카테고리

태그

질문:

2017년 11월 25일

댓글:

2017년 11월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by