MATLAB Answers

Looping through a random matrix to see if any element is >0.5

조회 수: 10(최근 30일)
Jaclyn McBride
Jaclyn McBride 3 Sep 2020
답변: per isakson 3 Sep 2020
I'm trying to loop through all rows and columns of a random matrix to test whether each element is greater than 0.5
I have this (which, clearly is not working):
for random_number_matrix = rand(4,8)
if random_number_matrix>0.5
display ('greater than')
end
end

  댓글 수: 0

댓글을 달려면 로그인하십시오.

답변(2개)

dpb
dpb 3 Sep 2020
random_number_matrix = rand(4,8);
isGt=(random_number_matrix>0.5);
display(random_number_matrix(isGt))

  댓글 수: 0

댓글을 달려면 로그인하십시오.


per isakson
per isakson 3 Sep 2020
Try
%%
for random_number_matrix = rand(4,8)
display (random_number_matrix)
end
and read the documentation on for

  댓글 수: 0

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by