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

2 次查看(过去 30 天)
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;

采纳的回答

John D'Errico
John D'Errico 2016-1-19
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by