MATLAB Answers

Access matrix location on one matrix with the data location on another matrix

1 view (last 30 days)
Rohan  Mehta
Rohan Mehta on 21 Jun 2019
Edited: madhan ravi on 21 Jun 2019
I have two matrix say A & B if I have data stored in A and the data location of desired values in B how could I access Values of matrix A who are located at locations B.

  0 Comments

Sign in to comment.

Accepted Answer

Chinmay Anand
Chinmay Anand on 21 Jun 2019
In case if A and B are vectors ,( 1 x n ) matrices
A(B) % It will give the values of A at indexes B

  3 Comments

Rohan  Mehta
Rohan Mehta on 21 Jun 2019
I want to keep values of A on location B as it is and set all other to zero.
Thanks for the help....

Sign in to comment.

More Answers (1)

madhan ravi
madhan ravi on 21 Jun 2019
Probably you want:
idx = setdiff(1:numel(A),B);
A(idx) = 0;

Sign in to answer this question.