sub2ind gives error: Error using sub2ind (line 43) Out of range subscript.
5 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!