Access the elements from 2D array based on the index
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pankaja Tanjore
am 3 Jul. 2015
Bearbeitet: Guillaume
am 3 Jul. 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 Kommentare
Akzeptierte Antwort
Guillaume
am 3 Jul. 2015
Bearbeitet: Guillaume
am 3 Jul. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!