如何修复 "Index in position 1 exceeds array bounds"

How to fix "Index in position 1 exceeds array bounds"

 x = gallery('uniformdata',[1,10],0);
 y = gallery('uniformdata',[1,10],1);
 [v,c] = voronoin([x(:) y(:)]); %returns an array V with vertices and a cell array C with a matrix for each cell of the diagram. 
 v = v( ~any( isnan( v ) | isinf( v ), 2 ),: );
 for ii=1:numel(c)
        v(c{ii},:) %contains the vertices to cell number ii, corresponding to centroid x,y(ii,:).     
 end

v(c{1},:) 似乎执行得很好,但是一旦它达到 v(c{2},:) 我就得到这个错误

"Index in position 1 exceeds array bounds (must not exceed 13)."

注意:numel(v) returns 13

我试过了for ii=1:numel(c)-1,但好像也没用

v = v(...) 更改数组 vc 中的索引不再匹配数组 v.

你应该删除那行代码。