How to empty part of column?

1 回表示 (過去 30 日間)
Seong Nam
Seong Nam 2017 年 4 月 25 日
コメント済み: Seong Nam 2017 年 4 月 26 日
Say I have an column array that looks something like this:
A = [1:10]'
A =
1
2
3
4
5
6
7
8
9
10
If I wanted to get rid of 3 to 8, what would be the command?

採用された回答

the cyclist
the cyclist 2017 年 4 月 25 日
A(A>=3 & A<=8) = [];
  1 件のコメント
the cyclist
the cyclist 2017 年 4 月 25 日
Note that this will remove elements with values equal to 3-8, not the elements in positions 3-8. (Your example is ambiguous about which of these you want.)

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

その他の回答 (1 件)

the cyclist
the cyclist 2017 年 4 月 25 日
  4 件のコメント
Walter Roberson
Walter Roberson 2017 年 4 月 25 日
196:2:-296 is the empty vector. When you use a positive increment (or use the default increment of 1) then if the last value is less than the first value, the result will be empty.
If you were to code
I(196:-2:-296) = [ ]
then 196:-2:-296 would not be empty, but you cannot use negative values as subscripts.
You probably want
I(I <= 196 & I >= -296) = [];
Seong Nam
Seong Nam 2017 年 4 月 26 日
This helped. Thank you!

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

カテゴリ

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