Retain rows and columns depending on the values of an array

2 ビュー (過去 30 日間)
Allan Paolo
Allan Paolo 2024 年 1 月 1 日
コメント済み: Voss 2024 年 1 月 1 日
Hi,
For example I have the square matrix:
A = [3 5 7 1 2; 2 4 3 1 5; 2 6 1 6 6; 4 7 5 1 1; 2 0 1 5 2]
Assuming I have the vector B, B = [1, 4, 5]
How do I get this output: A = [ 3 7 2; 2 1 6; 2 1 2]
Essentially it means A(2,:) = [], A(3,:) = [], A(:,2) = [], and A(:,3) = []. I was wondering if there is a more elegant way of doing this?

採用された回答

Voss
Voss 2024 年 1 月 1 日
A = [3 5 7 1 2; 2 4 3 1 5; 2 6 1 6 6; 4 7 5 1 1; 2 0 1 5 2];
B = [1, 3, 5];
A = A(B,B)
A = 3×3
3 7 2 2 1 6 2 1 2
(The example suggests B is [1 3 5], not [1 4 5].)
  2 件のコメント
Allan Paolo
Allan Paolo 2024 年 1 月 1 日
Ah yes. Thank you very very much!
Voss
Voss 2024 年 1 月 1 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by