フィルターのクリア

Add an element to a vector after taking difference

2 ビュー (過去 30 日間)
Christoph Meier
Christoph Meier 2015 年 9 月 3 日
コメント済み: Star Strider 2015 年 9 月 3 日
Dear Matlab community,
I am currently running some stationarity test, for which I take log-differences. However, if stationatiry tests still suggest non-stationarity, I would have to take the second difference.
The problem obviously is, that taking another difference changes the vector size, as now some of my variables are by 1 element shorter (those with the second difference).
I would like to add a zero as the first element to those column vectors, in order to restore equal dimensions.
It would basically look like this:
A =
X
X
X
B=
0
X
X
X
Thank you very much in advance!
Chris

採用された回答

Star Strider
Star Strider 2015 年 9 月 3 日
That is easy enough to do:
B = [0; A];
However another way might be to use interp1 to artificially ‘stretch’ ‘A’:
A = randi(9, 14, 1); % Create Data: ‘A’
Ax = [1:14]'; % Independent Variable Vector For ‘A’
Bx = [1:15]'; % Independent Variable Vector For ‘B’
B = interp1(Ax, A, Bx, 'linear', 'extrap'); % Interpolate/Extrapolate To Calculate ‘B’
I offer it as an alternative.
  2 件のコメント
Christoph Meier
Christoph Meier 2015 年 9 月 3 日
Thank you very much, that does exactly what I was after!
Star Strider
Star Strider 2015 年 9 月 3 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by