Info

この質問は閉じられています。 編集または回答するには再度開いてください。

concatonate time axis using a loop

1 回表示 (過去 30 日間)
Jordan Gallacher
Jordan Gallacher 2016 年 10 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件のコメント
Adam
Adam 2016 年 10 月 5 日
編集済み: Adam 2016 年 10 月 5 日
I assume your real problem is a little more complex than the example you posted because to get that time vector you can just do
t = 0:numel(t) - 1;

回答 (1 件)

Marc Jakobi
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 件のコメント
Jordan Gallacher
Jordan Gallacher 2016 年 10 月 5 日
Hi Marc,
Thanks! What about if the zero was not exactly zero and say 4 microseconds i.e. just a value less than the last time value before the logging reset?
Thanks,
Jordan.
Marc Jakobi
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!

Translated by