Plotting a set of rings using a single function

조회 수: 3 (최근 30일)
Arash A.
Arash A. 2020년 8월 13일
편집: VBBV 2025년 4월 18일
How to plot a set of rings (see the Figure below) using a single function, i.e., through the use of "for" loop?

채택된 답변

VBBV
VBBV 2020년 8월 14일
편집: VBBV 2025년 4월 18일
See also the m file for the code
clearvars close all
x = -100:0.5:200;
y = -100:0.5:200;
r = 50;
theta = 0:0.1:360;
for i = 1:length(x)
for k = 1:length(y)
if x(i) == 0 & y(k) == 0
for j = 1:length(theta)
xxc1(j) = r*cos(theta(j)) + x(i);
yyc1(j) = r*sin(theta(j)) + y(k);
end
plot(xxc1,yyc1,'b'); hold on ;axis([-100 200 -100 200]);
end
if x(i) == 0 & y(k) == 100
for j = 1:length(theta)
xxc2(j) = r*cos(theta(j)) + x(i); yyc2(j) = r*sin(theta(j)) + y(k);
end plot(xxc2,yyc2,'b'); hold on; axis([-100 200 -100 200]);
end
if x(i) == 100 & y(k) == 0
for j = 1:length(theta)
xxc3(j) = r*cos(theta(j)) + x(i); yyc3(j) = r*sin(theta(j)) + y(k);
end
plot(xxc3,yyc3,'b'); hold on ;axis([-100 200 -100 200]);
end
if x(i) == 100 & y(k) == 100
for j = 1:length(theta)
xxc4(j) = r*cos(theta(j)) + x(i); yyc4(j) = r*sin(theta(j)) + y(k);
end
plot(xxc4,yyc4,'b'); hold on ;axis([-100 200 -100 200]);
end
end
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 8월 14일
r = 50;
viscircles([0 0; 0 2*r; 2*r 0; 2*r 2*r], [r;r;r;r], 'color','k', 'linewidth', 1)
If you need to be able to plot fewer or more circles, you need to explain the pattern.
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 8월 14일
You have used fft() which is primarily for 1D signals. But for most of the x values, for any given x, there are either 0 or 4 associated y values. When there are multiple y values for a single x, then that is not a 1D signal.
It is possible to use fft() on a 2D signal, in which case it applies the transform along a single dimension. But if you were doing that then you would have to be very careful about what length() of the 2D signal would mean; most of the time length() would be wrong for that code.
So, what will F be, exactly: a 2D array that has circles drawn in it? If so then use insertShape https://www.mathworks.com/help/vision/ref/insertshape.html or use one of the techniques described at https://matlab.fandom.com/wiki/FAQ#How_do_I_create_a_circle.3F
Arash Ahmadivand
Arash Ahmadivand 2020년 8월 14일
Great explanation. Really appreciated Walter!

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

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by