tags:

views:

333

answers:

1

I have a function func that returns a vector a. I usually plot a and then perform further analysis on it. I have a certain scenario when once I try to plot a, I get a "??? Subscript indices must either be real positive integers or logicals" error. Take a look at the following piece of code to see the vector's behavior:

K>> a

a =
    5.7047    6.3529    6.4826    5.5750    4.1488    5.8343    5.3157    5.4454    

K>> plot(a)
??? Subscript indices must either be real positive integers or logicals.

K>> for i=1:length(a); b(i) = a(i); end;
K>> b

b =
    5.7047    6.3529    6.4826    5.5750    4.1488    5.8343    5.3157    5.4454    

K>> plot(b)
??? Subscript indices must either be real positive integers or logicals.

The scenario where this happens is when I call function func from within another function (call it outer_func), and return the result directly as outer_func's result. When debugging inside outer_func, I can plot a properly, but outside the scope of outer_func, its result has the above behavior.

What can cause this? Where do I start from?

+4  A: 

Do you, somewhere inside your function, have a line like this:

plot = something

In this case, plot is considered an array inside the function, and your error might occur.

As an aside: you could replace the loop by b=a.

Jonas
Yeah, stupid me. Thanks.
Roee Adler

related questions