Iterate through two matrices and get the item with the same index
Mostrar comentarios más antiguos
Hello,
I think this is a very simple problem. I have two matrices e.g.
A =
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
B =
5 5 5 5
6 6 6 6
7 7 7 7
9 9 9 9
Now I need for Matrix A the first index and for the Matrix B the same index, then the second index of A and the second index of B and so on. But i dont know how i can solve this in a double for loop.
I need the item at the index not just the index.
Hope u can help me. Thanks
2 comentarios
Sean de Wolski
el 22 de Ag. de 2014
What do you mean by "The first index"?
Can you provide the expected results for A and B above?
Antonio
el 22 de Ag. de 2014
Respuesta aceptada
Más respuestas (1)
Guillaume
el 22 de Ag. de 2014
bsxfun(@somefunction, A, B);
Where somefunction is a function that takes two scalars and returns a scalar.
2 comentarios
Sean de Wolski
el 22 de Ag. de 2014
No need for bsxfun if A and B are the same size.
somefunction(A,B)
Guillaume
el 22 de Ag. de 2014
You do, if somefunction operates on scalars
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!