位置2的索引无效。数组索引必须是正整数或逻辑值

时间:2019-05-05 23:08:09

标签: matlab

我遇到的错误是“位置2的索引无效。数组索引必须为正整数或逻辑值。”我的代码如下所示。该代码正在计算成本,并且在执行此操作时会检查是否已访问过的货架。当我启动程序时,发生此错误。为什么我要面对这个问题。如果您能帮助我,将不胜感激。谢谢!

%%
%This part calculates the cost between shelves
%So picker must visit every shelf which is not visited then return back to
%the entreance point
[DmatX, DmatY] = size(Dmat);
Shelfs = zeros(1, DmatY); % if 1 it means not visited if 2 it means visited
cost = 0;
current = 1;
path = ones (1,1);
index = 0;
for i = 1:DmatX
   temp = 100;
   Shelfs(1,current) = 2;
   for j = 1:DmatY
       if dMat(current,j) < temp && Shelfs(1,j) == 1 
           temp = dMat(current,j);
           smallest = dMat(current,j);
           index = j;
       end
   end
   if Shelfs(1, index) == 1
      path = [path; index];
      cost = cost + smallest;
      current = index;
   end
end
%calculates the last cost from last shelves to entrance point
path = [path; 1];
cost = cost + Dmat(current,1);
route = 'A0';

0 个答案:

没有答案