How to exclude more than 1 columns from a matrix?

조회 수: 46 (최근 30일)
Isti
Isti 2012년 4월 27일
I have a matrix like this: Data = [2,1,4,6,2;9,4,6,1,2;5,3,2,8,3;7,2,1,9,3;7,1,8,2,4]
2 1 4 6 2
9 4 6 1 2
5 3 2 8 3
7 2 1 9 3
7 1 8 2 4
then i want to exclude the column 3 and 5 from my new matrix. So it will be like this:
2 1 6
9 4 1
5 3 8
7 2 9
7 1 2
what to do? thanks before :')

채택된 답변

Richard
Richard 2012년 4월 27일
simple way would be:
Data(:,3) = []; Data(:,5) = [];
  댓글 수: 3
Richard
Richard 2012년 4월 27일
then you would remove one column first and then change the value accordingly, only a simple solution. Although I agree that Data(:, [3, 5]) = []; is better.
Isti
Isti 2012년 4월 28일
thanks Jan. actuallu when I used the solution above, there's a time the error about exceeded matrix is out.
so, solution from andrei below is same with you. and it works :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 4월 27일
Data = [2,1,4,6,2;9,4,6,1,2;5,3,2,8,3;7,2,1,9,3;7,1,8,2,4]
out = Data(:,[1 2 5])
  댓글 수: 4
Andrei Bobrov
Andrei Bobrov 2012년 4월 27일
Data(:,[3 5])=[]
Isti
Isti 2012년 4월 28일
thanks :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by