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

4 ビュー (過去 30 日間)
Jaclyn McBride
Jaclyn McBride 2020 年 9 月 3 日
回答済み: per isakson 2020 年 9 月 3 日
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

回答 (2 件)

dpb
dpb 2020 年 9 月 3 日
random_number_matrix = rand(4,8);
isGt=(random_number_matrix>0.5);
display(random_number_matrix(isGt))

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by