Replacing elements in a vector
Mostrar comentarios más antiguos
The values of an array match the index of elements in a vector. For example, the value of 5 in array1 below corresponds to whatever is in index 5 in vector1, i.e. the number 3 in this case. So how do I replace the value of the original number in array1 in the example by the number at the corresponding index in vector1? I realize this is a little confusing, so here's a mini example of what I want to do:
array1 = [1 2; 4 2; 5 5; 4 2];
vector1 = [2 1 1 4 3 4];
result = [2 1; 4 1; 3 3; 4 1];
Respuesta aceptada
Más respuestas (1)
Your example isn't consistent. I'm assuming you want this:
A = [10 20; 30 40; 50 60];
idx = [2 1; 1 4; 3 3];
B = A.';
B = B(idx)
1 comentario
L'O.G.
el 16 de Jul. de 2022
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!