Replacing repeated elements in a matrix
2 ビュー (過去 30 日間)
古いコメントを表示
Suppose i have matrix A=[ 8 8 8 8 7 7 7 4 2 17 18 18]
If a number is repeated , then I want to replace the last repeated element by a number say 5. The final matrix wil be
B= [8 8 8 5 7 7 5 4 2 17 18 5].
PLs suggest a code to generate B matrix?
2 件のコメント
Walter Roberson
2021 年 9 月 4 日
Suppose that
A=[ 8 8 8 8 7 7 8 4 2 17 18 18]
then would you want [ 8 8 8 5 7 5 8 4 2 17 18 5] or would you want [ 8 8 8 8 7 5 5 4 2 17 18 18] ? In other words is it "last in each run of 2 or more" or is it "last out of the entire vector" ? Oh yes an what about [8 3 8] -- should that be left alone because there are no places with consecutive values that are the same, or should it become [8 3 5] ?
採用された回答
その他の回答 (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!