How i can generate 2D matrix with unique values using 2D or 1D logistic map ?

3 ビュー (過去 30 日間)
Radhwan Jawad
Radhwan Jawad 2023 年 3 月 14 日
回答済み: Kush 2023 年 6 月 7 日
Hello Matlab community
I want to generate (n*n) matrix with unique values for each row and each column and the range of values in each cell must be between 0 and n-1 using 2D or 1D logistic map.
for example, if the size of matrix is 4*4 the output must be as below:
0 3 2 1
1 2 0 3
3 0 1 2
2 1 3 0
and i want this output is fixed for each run.

回答 (1 件)

Kush
Kush 2023 年 6 月 7 日
A simple solution to this could be creating an array of size n with values ranging from 0 to n-1, followed by appending this array after circular shifting into a matrix, this allows each element to be unique in its row as well as its column.
n = 4;
arr = 0:n-1;
matrix = zeros(n,n);
for i = 1:n
matrix(i,:) = circshift(arr,i);
end
matrix
matrix = 4×4
3 0 1 2 2 3 0 1 1 2 3 0 0 1 2 3
please find the documentation for circshift here:

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by