From: matt reister on 18 Jan 2010 16:48 "matt reister" <mattreister(a)hotmail.com> wrote in message <hj18dj$8a3$1(a)fred.mathworks.com>... > I have a rather simple matlab script that I am recieving the following error on: > Subscript indices must either be real positive integers or logicals. > > size = 10; > x = zeros(size,6); > for i = 0:size > x(i,:) = [i (i +1) (i +2) (i + 3) (i + 4) (i + 5) ]; > end > > I know the reason I aym recieving the error is because I am using i in the index of the x matrix, but it seems like i should be able to do this.... Does anyone know of a way the index a given row in a for loop like that? Thanks alll.... its was the zero index that was all.... still learning
From: Oleg Komarov on 18 Jan 2010 17:41 "Jan Simon" > Dear Oleg! > > > > x(i,:) = [i (i +1) (i +2) (i + 3) (i + 4) (i + 5) ]; > > > Third: 'i (i +1)' is not a valid expression in matlab. If you're trying to multiply, use the *. > > BTW: '[i (i + 1)]' is valid because there is a space between "i" and "(". It is equivalent to: > [i, i + 1] Jan, if you haven't pointed it out i wouldn't have noticed! I agree with, in fact i prefer using some more commas than making these kind of mistakes. To Matt, you can still avoid the loop if you just need to concatenate. Just remove the line with prod command and you'll have an incremental matrix (on both directions). Oleg
First
|
Prev
|
Pages: 1 2 3 Prev: Mean Shift Clustering Matlab code Next: Compiler 32 or 64 bit build options? |