Access the elements from 2D array based on the index
13 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!