How to find values in a matrix corresponding to the values in another matrix
2 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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);
See Also
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!