필터 지우기
필터 지우기

How can I delete even rows in a matlab Matrix

조회 수: 37 (최근 30일)
Mehdi Jaiem
Mehdi Jaiem 2020년 11월 23일
댓글: Mehdi Jaiem 2020년 11월 23일
Hello
My Idea consists in deleting every row with an even index (I wanted to test something).
But this code does not seem to work.
I get the error " Matrix index is out of range for deletion. "
Thank you
Y=magic(10)
%T = Y (1:2:end , 1:3:end );
T=Y
[a,b]=size(T);
for i = 1:a
r=rem(i,2);
if (r == 0)
T(i, :)=[];
end
T
end

채택된 답변

Stephan
Stephan 2020년 11월 23일
편집: Stephan 2020년 11월 23일
>> A = [1 2 3; 4 5 6; 7 8 9; 0 -1 -2]
A =
1 2 3
4 5 6
7 8 9
0 -1 -2
>> A(2:2:end,:) = []
A =
1 2 3
7 8 9
  댓글 수: 3
Stephan
Stephan 2020년 11월 23일
A(:, 1:3:end) = [];
will delete every third column without copying te wanted ones. If you dont want to use this syntax you have to use a loop - but why should you do this?
Mehdi Jaiem
Mehdi Jaiem 2020년 11월 23일
I want to get every third column starting from from the first one (it counts). Displayed will be : first, fourth, seventh etc...

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by