Plotting a set of rings using a single function
Show older comments
How to plot a set of rings (see the Figure below) using a single function, i.e., through the use of "for" loop?

Accepted Answer
More Answers (1)
Walter Roberson
on 14 Aug 2020
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 Comments
Arash Ahmadivand
on 14 Aug 2020
Thanks to all responders!
@Walter Roberson: The purpose of having all circles through a single function is the calculation of its fourier transform. Any further suggestions would be greatly appreciated!
Walter Roberson
on 14 Aug 2020
Your question asked about plotting, which is something that does not care about the exact mechanism as long as the visual results are right. But you cannot take the fft of a display, so it is not clear what you are asking?
Is your need to return an array of all 1 except where four circles are drawn in as a thin line of 0 (black) values? If so then computer vision toolbox insertShape
Arash Ahmadivand
on 14 Aug 2020
Thanks for your comment. Indeed, the problem is not just plotting the graph. I had a plan to obtain a function (F) for this arrangment of rings to utilize it in the following script to get its Fourier transform.
y=fftshift(fft(F));
N=length(y);
n=-(N-1)/2:(N-1)/2;
f=sqrt(y.*conj(y));
Walter Roberson
on 14 Aug 2020
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
on 14 Aug 2020
Great explanation. Really appreciated Walter!
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!