How do I delete rows and columns from a matrix

101 ビュー (過去 30 日間)
Kyle Gray
Kyle Gray 2016 年 1 月 21 日
回答済み: Lalit Dhurve 2020 年 1 月 29 日
I know this has been asked before, but I am new to matlab and all the answers I read through were jargon to me. So if someone could really dumb this down that would be wonderful. That being said, I have a simple matrix A= [1 2 3; 4 5 6; 7 8 9]. If I want to make A1 = the same matrix with the second row deleted and A2 = matrix A with the second column deleted. How would I do this? I can delete the end rows and columns, but can not seem to figure out a way to delete middle sections. Again, I know this has been asked so I appreciate your patients. Thanks in advance.
  1 件のコメント
Lalit Dhurve
Lalit Dhurve 2020 年 1 月 29 日
A= [1 2 3; 4 5 6; 7 8 9];
A1=A;
A1(2,:)=[];
A2=A;
A2(:,2)=[];
A1 , A2
DONE!!!

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

採用された回答

Star Strider
Star Strider 2016 年 1 月 21 日
Here are a couple different ways to do each:
A= [1 2 3; 4 5 6; 7 8 9];
A1 = A([1 3],:);
A1 = A;
A1(2,:) = [];
A2 = A(:, [1 3]);
A2 = A;
A2(:,2) = [];
The first method in each selects all but the second row or column, and the second method in each sets a specific row or column to ‘empty’ or ‘[]’. There are likely other methods as well, but those are the ones that come quickly to mind tonight.
  2 件のコメント
Kyle Gray
Kyle Gray 2016 年 1 月 21 日
Thank you for your help. This actually makes sense!
Star Strider
Star Strider 2016 年 1 月 21 日
My pleasure!

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

その他の回答 (1 件)

Lalit Dhurve
Lalit Dhurve 2020 年 1 月 29 日
A= [1 2 3; 4 5 6; 7 8 9];
A1=A;
A1(2,:)=[];
A2=A;
A2(:,2)=[];
A1 , A2

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by