From: Sofia Häggberg on
g=g(1:(length(x)-y+1));
From: John D'Errico on
"Sofia Häggberg" <hd.int.assNOSPAM(a)gmail.com> wrote in message <hhq31f$8vp$1(a)fred.mathworks.com>...
> g=g(1:(length(x)-y+1));

It is not how I understand it that matters. But
if you do not understand simple expressions
in matlab, you will never be able to use the
language. You will benefit from reading the
beginning tutorials in matlab.

Take it apart. First of all, what is x? A vector?
What does length(x) return? Try this if you do
not know:

help length

What is y? A scalar? What value does it take on?

What is

length(x) - y + 1

What does this do:

1:n

where n is a scalar?

What does g(1:n) do?

John
From: vortse a on
g is truncated to the size of x minus (y-1) elements.

so if g is 1x1000, x is 1x200 and y=5, the g will be truncated to 1x196

if g is smaller than length(x)-y+1, then you will get an error
From: Jan Simon on
Dear vortse a!

> g is truncated to the size of x minus (y-1) elements.
> so if g is 1x1000, x is 1x200 and y=5, the g will be truncated to 1x196
>
> if g is smaller than length(x)-y+1, then you will get an error

Except if [g] is a function, e.g. compare
sin = sin(1:10)
Fortunately, Matlab warns that "sin" has been previously used as a function then. Confusingly repeated calling this command reply the same by accident:
sin = sin(1:10)
sin = sin(1:10)
But of course this does not work for all indices:
cos = cos(0:0.1:1) % ==> warning appears
cos = cos(0:0.1:1) % ==> error...

Dear Sofia Häggberg!
Do not let this confuse you. Just do not use the same names for functions and variables.
Good luck and welcome to Matlab, Jan