【问题标题】:Error in loop: Attempted to access L(1); index out of bounds because numel(L)=0循环错误:试图访问 L(1);索引超出范围,因为 numel(L)=0
【发布时间】:2015-04-24 11:12:32
【问题描述】:

我尝试搜索,但似乎没有找到任何解决我的问题的方法。它说

试图访问 L(1);索引超出范围,因为 数字(L)=0。

Energy_Management_code 错误(第 64 行) a(k)=L(1);

这是出错的代码

%Arranging the data according to its location
L=NUMERIC(:,Location_no_column);
k=1;
a(k)=L(1);
p(1).loc=find(L/a(k)==1);
L(p(1).loc)=nan;

while max(isfinite(L))==1
   next=min(FIND(isfinite(L)));
   a(length(a)+1)=L(next);
   p(length(a)).loc=find(L/a(length(a))==1);
   L(p(length(a)).loc)=nan;
end

for i=1:length(a)
   Location(i).ID=a(i);
   Location(i).Place=p(i).loc;
   Location(i).Number=length(Location(i).Place);
end

【问题讨论】:

标签: matlab


【解决方案1】:

所以据我所见,错误很简单。

a(k) = L(1);

这一行出错是因为numel(L)=0,这意味着 L 为空。我猜这条线会创建一个空 L。

L = NUMERIC(:,Location_no_column);

检查NUMERIC(:,Location_no_column) 打印的内容并确认。

【讨论】:

    猜你喜欢
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    相关资源
    最近更新 更多