Azzera filtri
Azzera filtri

could anyone help me to solve the issue

1 visualizzazione (ultimi 30 giorni)
jaah navi
jaah navi il 5 Ago 2019
Risposto: Jon il 5 Ago 2019
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
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?
jaah navi
jaah navi il 5 Ago 2019
The place of the values in each column can be randomly shifted under the condition no two column should contain the maximum values at the same place.

Accedi per commentare.

Risposta accettata

Jon
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

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by