Move multiple rows with exceptions

4 vues (au cours des 30 derniers jours)
Rishi Balasubramanian
Rishi Balasubramanian le 23 Déc 2020
Hey
Consider I have a mxn matrix of binary data. I want to move the rows with 1s in it corresponding to a particular column except one row. How to achieve that?
%For example consider my matrix
% a b c d e f g h i j k l
H = [0 0 1 1 0 1 0 1 0 1 1 0; %1
0 0 0 1 0 1 1 0 1 0 1 0; %2
0 1 1 0 0 1 1 1 0 0 0 1; %3
0 1 1 0 1 0 1 0 1 0 0 1; %4
0 0 0 1 1 0 0 1 1 0 0 0; %5
0 1 0 0 1 0 0 0 0 0 1 0]; %6
% I want to move row 2&3 except row 4 corresponding to column g such that my resultant matrix must be
% a b c d e f g h i j k l
H = [0 0 1 1 0 1 0 1 0 1 1 0; %1
0 1 1 0 1 0 1 0 1 0 0 1; %4
0 0 0 1 1 0 0 1 1 0 0 0; %5
0 1 0 0 1 0 0 0 0 0 1 0; %6
0 0 0 1 0 1 1 0 1 0 1 0; %2
0 1 1 0 0 1 1 1 0 0 0 1]; %3
%Any help is appreciated. Thanks in advance

Réponses (1)

Cris LaPierre
Cris LaPierre le 23 Déc 2020
H = H([1 4:6 2 3],:)

Catégories

En savoir plus sur Resizing and Reshaping 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