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

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.

 Respuesta aceptada

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 comentarios

I want to keep values of A on location B as it is and set all other to zero.
Thanks for the help....
idx = setdiff(1:length(A),B); % indexes which are not in B
A(idx) = 0;
Thank you so much this works !!!

Iniciar sesión para comentar.

Más respuestas (1)

Probably you want:
idx = setdiff(1:numel(A),B);
A(idx) = 0;

2 comentarios

yes Exactly what I wanted
madhan ravi
madhan ravi el 21 de Jun. de 2019
Editada: madhan ravi el 21 de Jun. de 2019
Beware this method works even if A is a matrix more than 1 dimension unlike the other.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 21 de Jun. de 2019

Editada:

el 21 de Jun. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by