octave error: subscript indices must be either positive integers or logicals

indices, matlab, octave, sequence, sum

Solution

The error message explains what is wrong: you are trying to index an array with a number which is not a positive integer or logical. The only array indexing in your code is `x_n(n)`. And sure enough, the line `n=[0:1:N-1]` demonstrates that the index `n` is not positive, since `0` is not a positive number. Lesson: MATLAB/Octave always index from 1. I do suggest you real some tutorials as this is fundamental stuff which you'll need to know.

Problem

I'm trying to sum the product of an indexed vector and an indexed matrix like this: ``` k=[0:1:N-1] n=[0:1:N-1] x_n = sin(pi*n) N = size(x_n,2) _seqgen(x_n(n)*exp(k*n/N), n, 0..N-1) ``` but I get the error: ``` error: subscript indices must be either positive integers or logicals ``` What am I missing here? EDIT: I just realized that I missed the _plus function to sum the generated sequences. It should look like this: ``` k=[0:1:N-1] n=[0:1:N-1] x_n = sin(pi*n) N = size(x_n,2) _plus(_seqgen(x_n(n)*exp(k*n/N), n, 0..N-1)) ``` I still get the same error though...

Original source