could anyone help me to solve the issue
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Adam
il 5 Ago 2019
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?
Risposta accettata
Jon
il 5 Ago 2019
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!