Clear Filters
Clear Filters

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

1 view (last 30 days)
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.

Accepted Answer

KSSV
KSSV on 23 Jul 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)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!