MATLAB: Indexing values of an array based on values of one column

indexinglogical indexingmatrix

I'm looking to index a value in a certain row of a matrix, based on the values in one of the columns. For example, if I have an array like this:
[45 1 234 457
58 1 283 384
49 2 384 221
92 2 983 174
97 1 937 123]
How can I index the values in column 3 for values where the value in column 2 of the same row is 1? Without specifying the exact position of the value like column 3, row 1 and such. Is there a way to use logical indexing to do this?

Best Answer

Sounds like homework. Is it?
I don't think you can use logical indexing, at least immediately, because they are different lengths -- col 2 has 5 values while row 1 has 4 values. Try using intersect() or ismember() to find the values in common, then use logical indexing. Write back if you need help.