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

1 visualización (últimos 30 días)
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');

Respuesta aceptada

Ridwan Alam
Ridwan Alam el 18 de Dic. de 2019
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.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by