Delete some specific numbers from an array
古いコメントを表示
So, the problem is like this. I have an array of random numbers. For example [10 9 5 5 7 3 5 8 3 5 6 3 7 10 ]. First, I have to delete some of the numbers to make any point's value can not between its adjecent numbers. For example 9 is between 10 and 5, so I will delete 9. I tried to use a for loop but that does not work.
2 件のコメント
Walter Roberson
2019 年 10 月 2 日
Hint: sign(diff(TheVector)) will be the same for two entries in a row if the middle value is between the two other values (or if the three values are all equal)
Andrei Bobrov
2019 年 10 月 3 日
We delete 7, 7 is between 3 ans 10?
回答 (2 件)
Andrei Bobrov
2019 年 10 月 2 日
編集済み: Andrei Bobrov
2019 年 10 月 3 日
A = [10 9 5 5 7 3 5 8 3 5 6 3 7 10 ];
B = sign(diff(A(hankel(1:3,3:numel(A)))',1,2));
out = A( [true; prod(B,2) ~= 1 ; true] );
Rongyu Chu
2019 年 10 月 3 日
0 投票
3 件のコメント
Walter Roberson
2019 年 10 月 3 日
A<B<C does not mean that B must be in the range A to C. Instead it is ((A<B)<C) where the A<B returns 0 for false and 1 for true, and that 0 or 1 is compared to C.
Rongyu Chu
2019 年 10 月 3 日
Walter Roberson
2019 年 10 月 3 日
Index from highest to lowest so that when you delete, you do not need to examine the entries that "fell down".
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!