Algorithm to scan the total elements in a matrix randomly

1 次查看(过去 30 天)
Ex: A=[1 2 3;4 5 6];
I want to run a for loop for this matrix to compare a RANDOM element like
A(i,j)>=A(i,j+1) for the total elements but randomly, basically choosing an element A(i,j) randomly and compare it with A(i,j+1) but I need to cmpare all the elements in the matrix (6 elements )
Thank you in advance

回答(1 个)

David Hill
David Hill 2020-5-30
A=[1 2 3;4 5 6];
a=A<=A(randi(numel(A)));
  2 个评论
David Hill
David Hill 2020-5-30
If you take a random element of A.
A(randi(numel(A)))
and compare it to A (all elements), you get a logical matrix where logical 1 element meets the condition and logical 0 does not.
A<=A(randi(numel(A)));

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by