필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
MOHD
MOHD 2016년 1월 19일
편집: Walter Roberson 2016년 1월 19일
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에서 Board games에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by