How to have random groups( of 2 elements) from a squared matrix?
2 ビュー (過去 30 日間)
古いコメントを表示
I have a matrix A
A =
1 4 2 3
4 3 1 2
3 2 4 1
2 1 3 4
How to make different groups of two elements from this matrix? But the chosen elements (from the matrix A) have to be adjacent in the matrix A. for example A(1,1) & A(1,2) are adjacent and so they can be chosen. and A(1,1) & A(4,3) can't be chosen to make a group. I'd like to create a function which randomly choose these elements from A. And the function generates an other matrix containing the (2 by 2) different groupements randomly created. (for other examples see comment below)
thank you.
3 件のコメント
the cyclist
2013 年 6 月 10 日
Lorenz, if you read your post from the perspective of someone who has no idea of what you want, you might realize that you have neglected to give anywhere near enough detail. Please, don't make us guess at what you really want.
回答 (1 件)
Doug Hull
2013 年 6 月 10 日
There are 24 four connected pairs. Three per row, three per column.
I would generate a random integer from 1-numel(A) I would generate a random direction from 1-4 (North East South West) If the starting point and direction bring you out of the matrix. Draw again.
If it is a valid pairing, subset out what you are looking for using any indexing method you prefer.
Doug
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!