Selection of Matrix Elements without for loop

3 visualizaciones (últimos 30 días)
Amirhosein Valizadeh
Amirhosein Valizadeh el 5 de Jun. de 2019
Comentada: Amirhosein Valizadeh el 5 de Jun. de 2019
Hi.
I have a matrix of cooardinates like this :
A = [1 3;2 4;7 9];
And a Matrix 9x9:
B = rand(9);
How can I select B's elements in A cooardinest (for example : B(1,3) & B(2,4) & B(7,9)) without using a for loop.
Assuming that in my original code A has too many rows, ( more than 10K) and B is an image with too many points either.
As a matter of fact, I have some pixels' coordinates, and want to just update their's value in the original image by some formula. But I don't want to use for loop for selecting each pixel.

Respuesta aceptada

madhan ravi
madhan ravi el 5 de Jun. de 2019
B(sub2ind(size(B),A(:,1),A(:,2)))
  1 comentario
Amirhosein Valizadeh
Amirhosein Valizadeh el 5 de Jun. de 2019
Thanks, It worked.
My mistake was that I tried B(A), i didn't know the usage of sub2ind.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by