登录论坛

查看完整版本 : 奇怪的Matlab错误:“ ???下标索引必须是实数正整数或逻辑”


poster
2019-12-10, 20:41
我有一个函数func返回向量a 。我通常会绘制一个,然后对其进行进一步分析。我有一个特定的场景,当我尝试绘制a时,出现“ ??? Subscript indices must either be real positive integers or logicals ”错误。看一下下面的代码,看看向量的行为:

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调试时,可以正确地绘制图形,但是在outer_func的范围之外进行outer_func ,其结果具有上述行为。

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



回答:

您在函数内部的某处是否有这样的一行:

plot = something 在这种情况下,plot被认为是函数内部的数组,并且可能会发生错误。

顺便说b=a :您可以将循环替换为b=a 。



更多&回答... (https://stackoverflow.com/questions/2944752)