Access the elements from 2D array based on the index

23 ビュー (過去 30 日間)
Pankaja Tanjore
Pankaja Tanjore 2015 年 7 月 3 日
編集済み: Guillaume 2015 年 7 月 3 日
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

採用された回答

Guillaume
Guillaume 2015 年 7 月 3 日
編集済み: Guillaume 2015 年 7 月 3 日
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 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by