How to find values in a matrix corresponding to the values in another matrix

Hi, I have a MxN matrix and want to pick the values from a column corresponding to the values in another column. Is there some way of doing this?

Answers (1)

Hopefully this is rather self-explanatory:
% Get the two columns
anotherColumn = yourMatrix(:, 42); % or whatever column you want.
columnToSearch = yourMatrix(:, 13); % or whatever column you want to look in.
% Now get the value to look for
iWantThisValue = anotherColumn(23); % whatever....
% Find where that value occurs in the column you're searching.
% For example 0 0 0 1 1 0 0 1 0 0 1 1 1
logicalMapOfLocations = columnToSearch == iWantThisValue;
% Get the indexes, for example, [4 5 8 11 12 13]
indexes = find(logicalMapOfLocations);

1 Comment

Hi, Thanks for the help. TO be more specific, i will try to explain the problem in a better way.. Time=a(:,1); Phase=a(:,2); I want to pick the values of phase corresponding to particular values of time, say 10.5, 12.5 And the problem is that the row number of the particular time varies from one file to another.

Sign in to comment.

Asked:

on 15 Oct 2012

Community Treasure Hunt

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

Start Hunting!