Filter löschen
Filter löschen

could anyone help me to solve the issue

1 Ansicht (letzte 30 Tage)
jaah navi
jaah navi am 5 Aug. 2019
Beantwortet: Jon am 5 Aug. 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 Kommentare
Adam
Adam am 5 Aug. 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 am 5 Aug. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jon
Jon am 5 Aug. 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

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by