Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
MOHD
MOHD am 19 Jan. 2016
Bearbeitet: Walter Roberson am 19 Jan. 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;

Akzeptierte Antwort

John D'Errico
John D'Errico am 19 Jan. 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;

Weitere Antworten (0)

Kategorien

Mehr zu Board games finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by