MATLAB: How to solve this error

positive integer

function COM = jcoMatrix(I1) %Declare the function
% coMatrix : co-occurrence matrix
d_i = 0;
d_j = 1;
COM = zeros(256, 256); % Declare the size of the CCM
for i = 1:(size(I1, 1) – d_i)
for j = 1:(size(I1, 2) – d_j)
index_i = I1(i, j) + 1;
index_j = I1(i + d_i, j + d_j) + 1;
COM(index_i, index_j) = COM(index_i, index_j) + 1;
% To calculate the repeatition of pixel value so to generate CCM
end
end
Attempted to access COM(1.01408,2); index must be a positive integer or logical. Error in jcoMatrix (line 13)
COM(index_i, index_j) = COM(index_i, index_j) + 1;

Best Answer

Save the function file in different MATLAB script and ensure that filename must be same as function name, that is jcoMatrix.m
function COM = jcoMatrix(I1) %Declare the function
% coMatrix : co-occurrence matrix
d_i = 0;
d_j = 1;
COM = zeros(256, 256); % Declare the size of the CCM
for i = 1:(size(I1, 1) - d_i)
for j = 1:(size(I1, 2) - d_j)
index_i = I1(i, j) + 1;
index_j = I1(i + d_i, j + d_j) + 1;
COM(index_i, index_j) = COM(index_i, index_j) + 1;
% To calculate the repeatition of pixel value so to generate CCM
end
end
Next call the function from command window or another main MATLAB script by passing input argument I1 (matrix here)