Access the elements from 2D array based on the index
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pankaja Tanjore
el 3 de Jul. de 2015
Hello, I have an array A array with dimension 2x6 A=[10 20 30 40 50 60; 70 80 90 100 110 120];
and another 1D array with dimension 1x2 Indicies_Arr=[3 4];
Now i need to extract the data from Indicies_Arr that is 3 and 4 and extract corresponding element from A. I need to extract A(1,3) ,A(2,3) ,A(1,4) and A(2,4). I have to get the following output A(1,3)=30 A(2,3)=90
A(1,4)=40 A(2,4)=100 Function has to generic for any matrix size.
Please let know the function to get the above mentioned data from the matrix.
Looking forward to hear from you at the earliest.
Thanks Pankaja
0 comentarios
Respuesta aceptada
Guillaume
el 3 de Jul. de 2015
Editada: Guillaume
el 3 de Jul. de 2015
Note that your Indicies_Arr is badly named since it is actually a column index. I would rename it to column_indices or similar.
It's also not clear what output you want. Your description is not valid syntax for an output argument. Assuming you just want a matrix with the relevant elements:
A = [10 20 30 40 50 60; 70 80 90 100 110 120];
column_indices = [3 4];
out = A(:, column_indices)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!