Having Trouble with this Error "Index in position 2 is invalid. Array indices must be positive integers or logical values." It only occurs when I enter certain values for the translation. Such as -25 x-direction and +50 in the y-direction. But it will work if I enter in any decimal values such as (12.75,-19.3). Please help me out.
Note: A is an imported image
if (delta_x == 0 && delta_y == 0) % Allows the Orginal Image to be displayed
figure(1)
image(0:ynew-1,0:xnew-1,A) % display a matrix as an image
axis equal
axis ij % put 0,0 in UL corner
axis tight
colormap(gray(L)) % use an 8-bit grayscale
xlabel('y')
ylabel('x')
title('Original Image')
return
end
%Translation Matrix 3x3
Trans = [1 0 delta_x; 0 1 delta_y; 0 0 1];
InverseTrans = (inv(Trans)); %Inverse Mapping Begins
%Allocate Space
E = zeros(xnew, ynew,k);
for i=1:xold
for j=1:yold
% matrix math assumes origin is (0,0) not (1,1)
vw=InverseTrans*[i; j; 1]; % vw will be [v; w; 1]
v = vw(1);
w = vw(2);
if (v < 0 || v >(xold-1)) % Testing for Out of Bounds
E(i,j) = 0;
elseif (w < 0 || w >(yold-1)) % Testing for out of Bounds
E(i,j) = 0;
else
%Takes the Real INTEGER Part
v_fix = fix(v);
w_fix = fix(w);
v_fix1 = v_fix +1;%Indexing
w_fix1 = w_fix +1;
%Change in the Values
dX = v - v_fix;
dY = w - w_fix;
%Indexing Purposes **This is where I'm getting my error**
D1(i,j) = A(v_fix1, w_fix1);
D2(i,j) = A(v_fix1 + 1, w_fix1);
D3(i,j) = A(v_fix1, w_fix1 + 1);
D4(i,j) = A(v_fix1 + 1, w_fix1 + 1);
end
end
end```