I have a vector “Xt” where Xt dimensions are 12588 X 1. From this vector I apply this code:
S=sum((abs(Xt(2:end)-Xt(1:end-1))).^2);
which result in one number where S is a 1by1.
Now my objective is to construct a vector S (Nx1) where each value in S depends on J and K — for instance:
S=sum((abs(Xt(**J**:end)-Xt(**K**:end-1))).^2);
At first I thought of the following (I don’t want J do exceed 126):
for j=2:126 k=1:125,
S=sum((abs(Xt(j:end)-Xt(1:end-k))).^2);
end;
end;
I got the error: “Error using –
Matrix dimensions must agree.”
Is it a dimension issue plus a loop issue?
I just realized that this code works
for j=2:2 k=1:1;
S=sum((abs(Xt(j:end)-Xt(1:end-k))).^2);
end;
so it is really a matrix dimension issue!
To close this question:
that is how I solved this little problem 2 weeks ago:
very simple
(I was new to Matlab)