How to find a column with a specific set of numbers

조회 수: 4 (최근 30일)
Andrew Luce
Andrew Luce 2019년 5월 23일
답변: madhan ravi 2019년 5월 29일
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

답변 (2개)

Adam Danz
Adam Danz 2019년 5월 23일
편집: Adam Danz 2019년 5월 29일
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 2019년 5월 29일
Columns = find(all(matrix==[6;0;0]))

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by