How to stop for loop if E approximately = 0.8.?

1 visualización (últimos 30 días)
MOHD
MOHD el 19 de En. de 2016
Editada: Walter Roberson el 19 de En. de 2016
clc;
clear all;
close all;
[x,y]=meshgrid(-1:2/128:1);
circ=(x.^2+y.^2)<1;
A=ones(129,129);
B=A.*circ;
a1= 12849;
figure(1)
imagesc(B),colormap gray;axis image;axis off;
[x1,y1]=meshgrid(-1:2/128:1);
for r=0:0.001:1
circ1=(x1.^2+y1.^2)<r;
C=B.*circ1;
D=sum(sum(C));
E=D/a1
if (E ~= 0.8)
end
end
figure(2)
imagesc(C),colormap gray;axis image;axis off;

Respuesta aceptada

John D'Errico
John D'Errico el 19 de En. de 2016
tol = 1.e-12;
[x1,y1]=meshgrid(-1:2/128:1);
for r=0:0.001:1
circ1=(x1.^2+y1.^2)<r;
C=B.*circ1;
D=sum(sum(C));
E=D/a1;
if abs(E - 0.8) <= tol
break
end
end
figure(2)
imagesc( C ),colormap gray;axis image;axis off;

Más respuestas (0)

Categorías

Más información sobre Board games en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by