开发者

Strange Matlab error: "??? Subscript indices must either be real positive integers or logicals"

开发者 https://www.devze.com 2023-01-01 11:26 出处:网络
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 开发者_JAVA技巧\"??? Subscript in

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 开发者_JAVA技巧"??? 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消