sub2ind error: Out of range?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I don't understand the following error:
Error using sub2ind (line 73)
Out of range subscript.
The code
[R,C,Z] = size(imc);
[R,C] = meshgrid(1:1:R,1:1:C);
Z=Zf(R); %function
Z=floor(Z);
ind = sub2ind(size(image),R,C,Z)
Size(image)= 352 229 277
size(R )=352 229
size(C )=352 229
size(Z)=352 229
I use this line of coding for different images. In some images I get the error and in others not.
The size of the image, R, C and Z is the same in all the images, so I don't understand why the error is 'Out of range subscript'.
Has it something to do with the values of R, C and Z?
The values of R and C are constant for all images.
The Z values are dependent of the function Zf.
I tried this to keep the values of Z within the size of the images:
domein=size(imc);
domein_Z=domein(1,3);
for ii = 1:numel(Z)
if (Z(ii) > domein_Z | Z(ii) < 0)
Z(ii) = 50;
end
end
This doesn't make a difference.
2 Commenti
Walter Roberson
il 30 Gen 2020
Yes it is the values of those that is the problem. Each must be no larger in value than the size of the corresponding dimension.
Adam
il 30 Gen 2020
Yes, the size of R, C and Z is irrelevant (though they do have to be the same size as each other, of course). It is the values inside them that are being interpreted as subscripts.
Risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!