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

2 views (last 30 days)
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)

Image Analyst
Image Analyst on 15 Oct 2012
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
Sreeja
Sreeja on 15 Oct 2012
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.

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!