Identifying row in matrix, and find the corresponding row in other matrix

2 vues (au cours des 30 derniers jours)
Haya A
Haya A le 23 Juil 2018
Commenté : Haya A le 25 Juil 2018
Hi guys
I am trying to find a way to identify the row where a certain condition applied to cell, then go to another matrix and find the corresponding row or columns, and do some mathematical operation such multiplying and sum between the columns in the first matrix, which contains the found cell, with the same row in the second matrix.
for example, I am search for value X in matrix 1, after finding the cell with value X, I want to know the row number then go to matrix 2 to fetch the values of this row to multiply it with the first columns which contains the value X.
To be clear, the second matrix is Symmetric matrix, so columns or rows gives the same result.

Réponse acceptée

KSSV
KSSV le 23 Juil 2018
Read about logical indexing in MATLAB. Check the below example:
% Make some random data
vals = rand(15,1) ;
A = reshape(randsample(vals,9),3,3) ;
B = reshape(randsample(vals,9),3,3) ;
% Find A(2,1) in A and B
idx = A==A(2,1) ;
A(idx)
B(idx)

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by