Loop plus diff function with non-integers: Feasible?

2 次查看(过去 30 天)
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