From: matt reister on 18 Jan 2010 04:08 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?
From: Oleg Komarov on 18 Jan 2010 04:36 "matt reister" > 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? First of all don't use 'i' but 'ii'. Try to look for 'i' in the help. Second a matrix is indexed for all elements starting from 1 to end. So the element 0 doesn't exist. Third: 'i (i +1)' is not a valid expression in matlab. If you're trying to multiply, use the *. For i = 0 your expression returns 0 (if * is assumed) so why t start a loop from 0 at all? And to avoid any loop: [x,y] = meshgrid(0:5); x = x+y; Out = prod(x,2); Oleg
From: Oleg Komarov on 18 Jan 2010 04:45 "Oleg Komarov" > > And to avoid any loop: > [x,y] = meshgrid(0:5); > x = x+y; > Out = prod(x,2); > > Oleg Typo: replace [x,y] = meshgrid(0:5); with [x,y] = meshgrid(0:5,0:10); Oleg
From: Steve Amphlett on 18 Jan 2010 04:50 "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? Sadly, ML doesn't support zero-based indexing. x(0,:) isn't allowed. What a shame.
From: Oleg Komarov on 18 Jan 2010 05:44 "Steve Amphlett" > > 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? > > > Sadly, ML doesn't support zero-based indexing. x(0,:) isn't allowed. What a shame. Steve, why it's a shame? (I use just Matlab and T-SQL so i can't find any good reason to be asham for :)) Oleg
|
Next
|
Last
Pages: 1 2 3 Prev: Mean Shift Clustering Matlab code Next: Compiler 32 or 64 bit build options? |