2010-05-31 29 views
1

我有一个函数func,它返回一个向量a。我通常会绘制一个然后对其进行进一步分析。当我尝试绘制一个图形时,有一定的场景,我收到“??? Subscript indices must either be real positive integers or logicals”错误。看看下面的一段代码来看看向量的行为:奇怪的Matlab错误:“???下标索引必须是真正的正整数或逻辑”

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. 

在那里当我打电话功能func从另一个函数内发生这种情况时的场景(称之为outer_func),并直接为outer_func返回结果结果。在outer_func内部进行调试时,我可以正确绘图,但不在outer_func的范围内,其结果具有上述行为。

这是什么原因造成的?我从哪里开始?

+0

另请参阅[此问题](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol)for [generic解决此问题的方法](http://stackoverflow.com/a/20054048/983722)。 – 2013-11-27 15:45:13

回答

10

你,你的某处函数中,有这样一句台词:

plot = something 

在这种情况下,地块被认为是函数内部的数组,并可能出现你的错误。

顺便说一句:你可以用b=a代替循环。

+0

是的,我愚蠢。谢谢。 – 2010-05-31 18:15:41

相关问题