필터 지우기
필터 지우기

How do I replace values in a 400x400 matrix with values of 1x1001 array (r) and then replace all r <= 0.02 with 1 and r>0.02 with 0?

조회 수: 3 (최근 30일)
Hi,
I need to make a 400 x 400 matrix, with the values of r = [0.0001, 0.0002,......,0.1001] and then replace all r smaller or equal to 0.02 with an 1 and r bigger than 0.02 with 0.
I used this, but the matrix stays full of zeroes:
m=zeros(400,400)
for ii = 1:400
if r(ii)<0.02
m(ii) = 1;
else
m(ii) = 0;
end
end
can someone help me with this?

채택된 답변

David Hill
David Hill 2020년 6월 19일
r=.0001:.0001:.1001;
k=randi(1001,400);%I assumne you want randomly generated
m=r(k);
M=zeros(400);
M(m<=.02)=1;
M(m>.02)=0;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by