could anyone help me to solve the issue
1 回表示 (過去 30 日間)
古いコメントを表示
I am having a matrix
A=[0.0037 0.0036 0.0034 0.0033 0.0032 ;
0.0064 0.0066 0.0068 0.0070 0.0072 ;
0.0233 0.0236 0.0239 0.0243 0.0247 ;
1.5367 1.5125 1.4787 1.4317 1.3691 ;
0.0396 0.0413 0.0428 0.0441 0.0452 ];
In the above matrix for all columns the maximum value is present in the fourth row.
I want to shuffle the values in each column such that no two columns should contain the maximum value at tha same place.
could anyone please help me on this.
2 件のコメント
Adam
2019 年 8 月 5 日
How are you defining 'shuffle'? Do you want them to retain their ordering, but in a circular shift down each column or is a random ordering fine so long as the max value is in a different row for each column?
採用された回答
Jon
2019 年 8 月 5 日
If I am understanding your problem correctly you could do something like this:
% define matrix of value
A=[0.0037 0.0036 0.0034 0.0033 0.0032 ;
0.0064 0.0066 0.0068 0.0070 0.0072 ;
0.0233 0.0236 0.0239 0.0243 0.0247 ;
1.5367 1.5125 1.4787 1.4317 1.3691 ;
0.0396 0.0413 0.0428 0.0441 0.0452 ];
% find current row number where each column maximum occurs
[~,idx] = max(A)
% define a random permutation which will give the new row locations of the
% maximum for each column
numColumns = size(A,2);
inew = randperm(numColumns);
% calculate required shift to achieve the new pattern
iShift = inew - idx;
% make new shuffled matrix
Anew = zeros(size(A)); % preallocate
for k = 1:numColumns
Anew(:,k) = circshift(A(:,k),iShift(k))
end
0 件のコメント
その他の回答 (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!