奇怪的Matlab错误:"???下标索引必须是真正的正整数或逻辑"

Roe*_*ler 1 matlab plot

我有一个func返回向量的函数a.我通常绘制一个然后对其进行进一步分析.我有一个特定情况,一旦我尝试绘制一个,我得到一个" ??? Subscript indices must either be real positive integers or logicals"错误.看一下下面的代码片段来看看vector的行为:

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.
Run Code Online (Sandbox Code Playgroud)

发生这种情况的情况是当我func从另一个函数中调用函数(调用它outer_func),并直接返回结果作为outer_func结果.在里面调试时outer_func,我可以正确绘制,但在范围之外outer_func,其结果具有上述行为.

是什么导致这个?我从哪里开始?

Jon*_*nas 10

你,在你的函数内部,有这样的一行:

plot = something
Run Code Online (Sandbox Code Playgroud)

在这种情况下,绘图被视为函数内部的数组,您的错误可能会发生.

除此之外:您可以替换循环b=a.