How can I delete even rows in a matlab Matrix
37 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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
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?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!