sub2ind gives error: Error using sub2ind (line 43) Out of range subscript.

조회 수: 1 (최근 30일)
natasha
natasha 2019년 12월 18일
편집: natasha 2019년 12월 18일
Below is a script (not my own, but I have been modifying it to run on a specific data set) that gives me an error in the final line: Error using sub2ind (line 43) Out of range subscript.
I am not sure how to solve this. I have tried:
k=find(~ys') and k=find(~xs')
to find where there are potential indicies of zero value. From these I get the output:
k = 0×1 empty double column vector
Any help would be greatly appreciated.
src1 = [-12579.27069; 4262.64531]
rec1 = [-12814.28064; 4874.32785]
mult=10
ds = checkerboard(10,50,57) > 0.5;
ds = padarray(ds,[2,2]); % shifted checkerboard
ds = (ds(:,:)-0.5)/5;
sTrue = ds+0.4;
sc=size(sTrue);
lc=length(sTrue(:));
steps = ceil(1.5*max(sc));
av=single([]);
ii=single([]);
jj=single([]);
v0 = rec1-src1;
vn = norm(v0);
v = v0/vn;
points = src1+v*linspace(0,steps,steps*mult);
pcheck = sum((points-rec1).^2);
[u,i]=min(pcheck);
inds = floor(points(:,2:i));
npoints=length(inds);
xs=inds(1,:);
ys=inds(2,:);
ds_int = (vn/npoints);
indA = sub2ind(sc,ys',xs');

채택된 답변

Ridwan Alam
Ridwan Alam 2019년 12월 18일
In your code, xs contains negative values, which can't be the column indices.
Also, sc is only 1004x1144. But the values of xs and ys are much off for row and col indices of a matrix of size sc.
Seems like you're calculating the points wrong somehow.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by