MATLAB Answers

0

How to find a column with a specific set of numbers

Asked by Andrew Luce on 23 May 2019
Latest activity Answered by madhan ravi
on 29 May 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

  0 Comments

Sign in to comment.

2 Answers

Answer by Adam Danz
on 23 May 2019
Edited by Adam Danz
on 29 May 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

  0 Comments

Sign in to comment.


Answer by madhan ravi
on 29 May 2019

Columns = find(all(matrix==[6;0;0]))

  0 Comments

Sign in to comment.