Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
concatonate time axis using a loop
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a time axis which keeps resetting due to drop outs in the logging e.g.
t = 0,1,2,3,4,5,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,0,1,2 and so on....
What is the most efficient piece of code to generate the new time vector so that the zeros continue on from the last time value before the dropout.
t = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
Thanks!
Jordan.
답변 (1개)
Marc Jakobi
2016년 10월 5일
This should do it:
t = [0,1,2,3,4,5,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,0,1,2];
idx = find(ismember(t, 0));
for i = 2:length(idx)-1
t(idx(i):idx(i+1) - 1) = t(idx(i):idx(i+1) - 1) + idx(i) - 1;
end
t(idx(end):end) = t(idx(end):end) + idx(end) - 1;
댓글 수: 2
Marc Jakobi
2016년 10월 5일
편집: Marc Jakobi
2016년 10월 5일
Then I would I would replace
idx = find(ismember(t, 0));
with
idx = find([0, diff(t)] <= 0);
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!