How can I create a random matrix without repeating any value between column
古いコメントを表示
I get two columns with the same value when I generate the matrix. For example,
1 1 3 2 4
4 4 1 4 3
2 2 2 3 1
3 3 4 1 2
I want to get something like the 10 combinations from the 24 combinations(4 factorial).
1 1 3 2 4 1 2 4 3 2
2 4 1 4 3 3 3 1 2 1
3 2 2 3 1 4 1 3 4 3
4 3 4 1 2 2 4 2 1 4
I need the matrix to form the chromosomes for GA.
3 件のコメント
Steven Lord
2023 年 5 月 23 日
It is not at all clear to me how you obtained the second of those matrices from the first. Some of the columns (like columns 2, 3, 4, and 5) are copies of columns from the first matrix, but some (like columns 1 and 6) are not. What rules specifically do you need to follow in generating that second matrix from the first?
Dyuman Joshi
2023 年 5 月 23 日
As Steven mentions, it's not clear what is the pattern you are following to obtain the output.
From a cursory glance, it can be observed from the output that the 1st column is sorted and the 6th column corresponds to the indices of the sorted values of the 1st column. But the it's not clear what's the logic behind the columns 7-10.
Wan
2023 年 5 月 28 日
採用された回答
その他の回答 (1 件)
You can use reshape(), randperm(), numel(), size() fcns to create ramdom swaps of the already existing matrix elements:
A1 = [1 1 3 2 4;
4 4 1 4 3;
2 2 2 3 1;
3 3 4 1 2];
A_new = [reshape(A1(randperm(numel(A1))), size(A1)), reshape(A1(randperm(numel(A1))), size(A1))]
2 件のコメント
Dyuman Joshi
2023 年 5 月 23 日
@Sulaymon Eshkabilov, every column must contain all the numbers [1 2 3 4]. The output from your code does not.
Wan
2023 年 5 月 28 日
カテゴリ
ヘルプ センター および File Exchange で Symbolic Math Toolbox についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!