MATLAB: I am getting the error “Subscript indices must either be real positive integers or logicals.” just want to know what is the cause of this error.. how to resolve it I have already checked another ans for the same error but could’t able to remove err

image processing

%
% read an image %%
img = imread('path_to_image'); %%any image
gray = rgb2gray((img));
%%filter mask
prx= [1,0,1;-1,0,1;-1,0,1];
[hk,wk]= size(prx);
pad1 = ( wk-1) / 2;
%%zero padding
image1 = padarray(gray,[pad1,pad1],'both');
%%image1 = round(image1); %%I tried to convert it in logical and double but got the same error at roi line
[ih,iw] = size(image1);
output = zeros(ih,iw);
[rows,cols] = size(image1);
for y=pad1:pad1+ih
for x=pad1:pad1+iw
roi = image1(y-pad1:y+pad1+1,x-pad1:x+pad1+1); %%error at this line()
k= roi.*prx;
end
end