Filter löschen
Filter löschen

Move multiple rows with exceptions

1 Ansicht (letzte 30 Tage)
Rishi Balasubramanian
Rishi Balasubramanian am 23 Dez. 2020
Beantwortet: Cris LaPierre am 23 Dez. 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

Antworten (1)

Cris LaPierre
Cris LaPierre am 23 Dez. 2020
H = H([1 4:6 2 3],:)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by