Because
1:1:(size(velocity)-1)
does not do what you want it to.
velocity
is an 1xN
array, size(velocity)
therefore returns [1 N]
. The colon operator only cares about the first value in the array and the array you want to loop over ends up being empty since
1:1:[1 N]-1 == 1:1:1-1 == 1:1:0 == Empty matrix
Due to problems like these you should always use either of the following instead of size(var)
when constructing loops:
size(var, n) % Returns the size of the nth dimension of var
length(var) % Returns the size of the largest dimension of var
numel(var) % Returns the number of elements in var