MATLAB: Finding values in a matrix

findmatrix

Hi all,
I have a problem that I don't know quite how to describe. I am trying to find all data points that are above a certain threshold in a matrix.
[row,col]=find(TBin>=timeS(k1) & TBin<=timeS(k1+1));
Which works. It gives me the row and column coordinates of the points that meet that criteria in an array. Then I want to get the data points that correspond to those locations.
TiP=TBin(row,col);
What this gives me is a 250 x 250 matrix where all the values down a column are right, but for some reason each value is repeated 250x across all of the other columns. Is there a way to only get a single column with the correct answers? It confuses me that the output is a matrix. I know I can select only one column from the matrix but I was hoping for a more efficient way.
Thanks!

Best Answer

You need to use logical indexing, not find():
logicalIndexes = TBin>=timeS(k1) & TBin<=timeS(k1+1) % k1 is a vector.
% If k1 is a vector, then logicalIndexes is also a vector.
% Extract the values
outputValues = TBin(logicalIndexes)