フィルターのクリア

How to specifically select columns from a matrix?

2 ビュー (過去 30 日間)
Benson Gou
Benson Gou 2018 年 10 月 6 日
編集済み: Stephen23 2018 年 10 月 7 日
Dear All,
For a given 2 columns matrix A. For example
Can I extract the first 3 elements in the 2nd columns and the 4th and 5th elements in the first column by one commend?
I tried the following way but failed: First, I defined an array as follows,
Then I did A(:,r) and it did not work.
Thanks a lot. Bei Gou

採用された回答

Stephen23
Stephen23 2018 年 10 月 7 日
編集済み: Stephen23 2018 年 10 月 7 日
>> A = [1,2;3,4;5,6;7,8;9,10]
A =
1 2
3 4
5 6
7 8
9 10
>> R = [1,2,3,4,5];
>> C = [2,2,2,1,1];
>> X = sub2ind(size(A),R,C);
>> A(X)
ans =
2 4 6 7 9

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by