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
0 个评论
回答(1 个)
David Hill
2020-5-30
A=[1 2 3;4 5 6];
a=A<=A(randi(numel(A)));
2 个评论
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 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!