How to find a column with a specific set of numbers

3 Ansichten (letzte 30 Tage)
Andrew Luce
Andrew Luce am 23 Mai 2019
Beantwortet: madhan ravi am 29 Mai 2019
Hello so I have a matrix like this:
0 5 5 0 0 6 11 11 6 6
0 0 5 5 0 0 0 5 5 0
0 0 0 0 0 0 0 0 0 0
How can I find which columns has the [6;0;0] which in this case is columns 6 and 10?
Thank you

Antworten (2)

Adam Danz
Adam Danz am 23 Mai 2019
Bearbeitet: Adam Danz am 29 Mai 2019
Use ismember() with 'rows' option.
% m is your matrix
colIdx = ismember(m.', [6 0 0], 'rows')'; % note the transpose of m
colNum = find(colIdx); % column numbers that match 6;0;0

madhan ravi
madhan ravi am 29 Mai 2019
Columns = find(all(matrix==[6;0;0]))

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by