From: Sofia Häggberg on 3 Jan 2010 07:37 g=g(1:(length(x)-y+1));
From: John D'Errico on 3 Jan 2010 08:24 "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 3 Jan 2010 09:45 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 3 Jan 2010 11:14 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
|
Pages: 1 Prev: multiple bvp4c? Next: How to connect model from simpowersystems to model from simscape |