How to find values in a matrix corresponding to the values in another matrix
Afficher commentaires plus anciens
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?
Réponses (1)
Image Analyst
le 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 commentaire
Sreeja
le 15 Oct 2012
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!