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?

Roee Adler
  • 33,434
  • 32
  • 105
  • 133
  • Also see [this question](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) for [the generic solution to this problem](http://stackoverflow.com/a/20054048/983722). – Dennis Jaheruddin Nov 27 '13 at 15:45

1 Answers1

10

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
  • 74,690
  • 10
  • 137
  • 177