How to remove certain rows and columns in a matrix?

2 ビュー (過去 30 日間)
Ali
Ali 2020 年 7 月 10 日
コメント済み: Ali 2020 年 7 月 10 日
I have this 8x8 matrix and I want to preserve only the 1, 2, 7 and 8 (for now, these numbers change based on a computation) rows and column to get a 4x4 output matrix. How can I delete other columns and rows or copy the forementioned rows and columns to a new matrix with a new 4x4 structure?
Keep in mind that the desired rows and columns change based on a function computation.
A = [
0 1 0 0 0 0 0 1
1 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 1 0 0 0 0 0 1
1 0 0 0 0 0 1 0 ]
Desired output (for this context):
A = [
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0 ]
  2 件のコメント
Stephen23
Stephen23 2020 年 7 月 10 日
>> B = A([1,2,7,8],[1,2,7,8])
B =
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0
Ali
Ali 2020 年 7 月 10 日
Thanks @Stephen, nice and clean solution. ;)

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

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 10 日
編集済み: madhan ravi 2020 年 7 月 10 日
w = A([1,2,7,8], :)
Wanted = w(:, [1,2,7,8])
  1 件のコメント
Ali
Ali 2020 年 7 月 10 日
編集済み: Ali 2020 年 7 月 10 日
You're a lifesaver buddy! Respect! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by