Azzera filtri
Azzera filtri

Move multiple rows with exceptions

1 visualizzazione (ultimi 30 giorni)
Rishi Balasubramanian
Rishi Balasubramanian il 23 Dic 2020
Risposto: Cris LaPierre il 23 Dic 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

Risposte (1)

Cris LaPierre
Cris LaPierre il 23 Dic 2020
H = H([1 4:6 2 3],:)

Categorie

Scopri di più su Resizing and Reshaping 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!

Translated by