Indexing Tips: extend a time series to be cyclic

Hi everyone,
I'm trying to write some code to get stats on a time series and I'm looking for tips about handling negative and zero indices, i.e. I want an efficient way to tell Matlab that when an index is negative (say -n) to choose the element of the time series n+1 steps from the end. So far I'm using if statements but it's slowing down the code quite a bit.
Any advice?
-Tom

回答 (2 件)

Honglei Chen
Honglei Chen 2012 年 8 月 1 日
編集済み: Honglei Chen 2012 年 8 月 1 日

0 投票

Not sure if it solves your question exactly but here is something that could be helpful. Say your data is 5 samples long
N = 5;
idx = -N:N
idx_new = mod(idx-1,N)+1

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2012 年 8 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by