Looping through a random matrix to see if any element is >0.5
3 次查看(过去 30 天)
显示 更早的评论
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
2020-9-3
random_number_matrix = rand(4,8);
isGt=(random_number_matrix>0.5);
display(random_number_matrix(isGt))
0 个评论
per isakson
2020-9-3
Try
%%
for random_number_matrix = rand(4,8)
display (random_number_matrix)
end
and read the documentation on for
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!