Loop plus diff function with non-integers: Feasible?

조회 수: 2 (최근 30일)
Charles Martineau
Charles Martineau 2012년 5월 31일
hi all,
I am not sure if this is easy or not but I am struggling with the following:
Say that I have a vector Xt (10,000*1) of daily stock returns. I built this partition function formula:
for j=1:125;
E=Xt(1:j:end);
EE=diff(E(2:end));
EEE=diff(E(1:end-1));
Sq(j)=sum(abs(EE-EEE).^3);
end;
where j=1:125 is the various intervals that I wish to calculate the difference EE-EEE from the vector Xt. Now, what is the most efficient way for me to calculate the EE-EEE using non integer numbers?
If I construct a new vector as follow:
expo=0:1000;
A=1.1*ones(size(expo));
ddt=A.^expo;
in ddt there are numbers in which I would like to implement rather than 1:125.
(ddt vector looks like [1 1.1 1.21 1.331 1.4641 1.61051 1.771561 1.9487 2.14358]
What's the best way for to achieve this? In my orignal formula, I generate a Sq vector of size 1X125 for integer intervals but I want more numbers therefore I must turn to non-integer numbers.
Thank you very much for the help!

채택된 답변

Oleg Komarov
Oleg Komarov 2012년 5월 31일
If I understood correctly, you want to partition non non integer ontervals. Say you want to select Xt every 1.331 step.
Since you have values only at Xt(1), Xt(2) etc... and not on Xt(1.331), Xt(2.662) etc but you still want to get those number then you can interpolate.
  댓글 수: 2
Charles Martineau
Charles Martineau 2012년 5월 31일
Yes exactly! Basically the best is for me to generate a new Xt vector with elements 1.331 2.662. ... and then take the diff of this vector.
Oleg Komarov
Oleg Komarov 2012년 5월 31일
Use interp1() to generate the interpolated values of Xt.

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

추가 답변 (1개)

Charles Martineau
Charles Martineau 2012년 5월 31일
If anyone can help... I am really struggling with this one!

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by