I want to be able to delete after ten 5s (or after some number of 5s in the array) the remaining values in the array without prior knowledge of the location (^).
Removing non unique elements from an array after n entries
1 次查看(过去 30 天)
显示 更早的评论
If I have an array:
[1 2 3 4 5 6 8 1 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 .... 5]
^
How can I remove the remaining 5s after say, here?
2 个评论
采纳的回答
Image Analyst
2014-6-30
out = yourVector(1:18);
1 个评论
Image Analyst
2014-6-30
Regarding your additional comment:
m = [1 2 3 4 5 6 8 1 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5]
maxNumber = 7; % How many 5's do you want to keep.
indexes = find(m == 5)
m_out = m(1 : indexes(maxNumber))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!