What's wrong with my formula? - Can't solve my matrix dimension issue...
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi everyone, My objective is the following: - to make this equation in matlab: see equation (a partition function) here:
some information on the equation: * q can take any value between 1 to 5 - for now I assume 2. * X(i delta t) is the change in price for interval i and X(i deltat t + deltat t ) is the change in price in the following interval.
I start by creating my vector Xt which is of size 12588 X 1. Think of each element of the vector as a price of a stock for each day.
My final result should be a vector where each element is the result of the above formula for different size of interval.
This is my current formula so far in matlab:
for j=2:126,
S(j-1)=sum((abs((Xt(j+1:end)-Xt(j:end-j+1))-(Xt(j:end-j+1)-Xt(1:end-j)))).^2);
end;
Error using -
Matrix dimensions must agree.
j=2:126 is the various interval in the change of price that I wish to compute.
If someone can help me out with my problem... please! I've been struggling on this one for a while now! Thank you!!
0 comentarios
Respuesta aceptada
Más respuestas (3)
Walter Roberson
el 27 de Mayo de 2012
Xt(j:end-j+1) is not the same size as Xt(1:end-j)
0 comentarios
Image Analyst
el 27 de Mayo de 2012
What I do in situations like this is to not try to cram so many things into one expression. If you make up some intermediate variables you will quickly see the problem:
Xt = rand(12588, 1);
for j=2:126
x1 = Xt(j+1:end);
x2 = Xt(j:end-j+1);
v1 = x1 - x2;
v2 = Xt(j:end-j+1)-Xt(1:end-j);
S(j-1)=sum(abs(v1-v2).^2);
end
Note how x1 is 12585 elements long and x2 is 12584 elements long. Thus you can't subtract them.
0 comentarios
Charles Martineau
el 27 de Mayo de 2012
1 comentario
Image Analyst
el 27 de Mayo de 2012
Yes, it will work in the special case of using ONLY 2 but not in the general case. I'm not sure why you were expecting different sized vectors and why you thought that would work. And I'm not really sure what X(i deltat t + deltat t ) means. I'm not familiar with that terminology. Would that be the same as X(i * deltat + deltat)?
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!