How to find a number but if it repeats immediately after, take the first value.
2 次查看(过去 30 天)
显示 更早的评论
I want to be able to find the index of the first 5 in but ignore the other 5's if they are immediately right after.
In the example below, there would be three 5's I would want to keep.
A = [0 5 0 5 5 0 0 0 5 5 5 5 5 0 0 0]
b = A == 5;
c = find(b == 1);
A = [0 5(keep) 0 5(keep) 5 0 0 0 5(keep) 5 5 5 5 0 0 0]
0 个评论
采纳的回答
更多回答(1 个)
Sulaymon Eshkabilov
2021-4-7
Here is an easy solution to your exercise:
A = [0 5 0 5 5 0 0 0 5 5 5 5 5 0 0 0];
IND = find(A==5);
C = A(IND(1:5));
Good luck.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!