Create a circle in the matrix with zeros

21 visualizaciones (últimos 30 días)
Ivan
Ivan el 19 de Oct. de 2020
Comentada: Ivan el 12 de Nov. de 2020
Hi!
I have a Matrix D=onse(N,N).
I would like to make a circle with radius R at the center at (i0,j0) with filled zeros.
I wrote something like that but it takes so long time in my sub-loop to calculate it. Do you have a better idea how can we make such "0" circle inside the matrix?
for i=1:N
for j=1:N
if ((i-i0)^2+(j-j0)^2)<(R^2)
D(i,j)=0;
end
end
end
Thank you for your help!

Respuesta aceptada

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam el 19 de Oct. de 2020
% values
N=100;
D=ones(N,N);
i0=10;
j0=20;
R=8;
% filter indise circle
[x,y]=meshgrid(1:N);
D((x-i0).^2+(y-j0).^2<R^2)=0;

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by