find first line that satisfies condition; skip next few; then find next line that satisfies condition

조회 수: 1 (최근 30일)
I have a long column of #'s. I want to find and replace values >4.8 with 10000 so that later code can find these spots. This works ok:
stim_time = find(TTL_column>4.8);
TTL_column(stim_time) = 10000;
However, there are ~3-6 points all grouped together that have almost the same time stamp (e.g., 15870,15871,15872,15873). I only want to replace the first one of these with the #10000 (e.g., only the value at 15870 = 10000). I am totally lost on how I'd get this code to replace only the first spot in each group and not the whole group, since each group has an unequal number of points. Any help would be greatly appreciated!
stim_time =
15870
15871
15872
15873
49863
49864
49865
49866
49867

채택된 답변

Matt J
Matt J 2019년 3월 24일
편집: Matt J 2019년 3월 24일
idx = diff([0;TTL_column(:)>4.8])>0;
TTL_column(idx) = 10000;
  댓글 수: 3
Kathleen Hupfeld
Kathleen Hupfeld 2019년 3월 25일
or a way to count how many substitutions were made that's more efficient than this? :)
total = 0;
for i = 1 : length(idx)
if idx(i)==1
total=total+1;
end
end
total

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by