Effacer les filtres
Effacer les filtres

Alternate for flipr command in matlab

4 vues (au cours des 30 derniers jours)
Bathrinath
Bathrinath le 1 Mar 2012
Hi,
m = 3; n = 8; There are 8 elements in A
A = [33,47,44,49,40,21,45,48];
After sorting in descending order
A = [49,48,47,45,44,40,33,21]
I need final matrix
final =[ 49 48 47 ; 40 44 45 ; 33 21 ]
In first two rows 3 elemets has to be there.
In third row 2 elements has to be there,because n = 8.
Second row is printed in reverse order.
I cant use "flipr" in this case bcoz matrix is not same size.
Alternate rows has to be printed in reverse order.
Advice me regarding this.

Réponses (2)

Walter Roberson
Walter Roberson le 1 Mar 2012
You cannot create a numeric matrix which has different number of elements in various rows or columns. 8 elements cannot be arranged in to a 3-row numeric matrix -- not without adding an extra element.
  1 commentaire
Andrei Bobrov
Andrei Bobrov le 1 Mar 2012
Hi Walter! I agree with you.

Connectez-vous pour commenter.


Andrei Bobrov
Andrei Bobrov le 1 Mar 2012
A = [33,47,44,49,40,21,45,48];
m = 3;
n = numel(A);
out = nan(m,ceil(n/m));
out(1:n) = sort(A,'descend');
out(:,2:2:end) = out(end:-1:1,2:2:end);
out = out'
  1 commentaire
Bathrinath
Bathrinath le 2 Mar 2012
Thanks andrei bobrov,your code works

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by