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!