The output you require is not very clear from your post. However, I believe you have a matrix and you are trying to count how many of the matrix elements are repeated in a row by row basis.
I have prepared the below code for you to understand how to iterate through the matrix element by element to compare each elements with other in its row.
The code is pretty self-explanatory. If you still have trouble, please do not hesitate to say so.
(NOTE : There are many more efficient ways to do this taks than the code below.)
(NOTE2: My code tells how many elements occured in a row in the output sentence you will see below. If you only want the number of "repeating" elements just subtract 1 from the corresponding result.)
Hope this helps.
function resultList = findRepeatingElementsRow()
matrix = randi(10,5);
numberOfRows = size(matrix, 1);
numberOfColumns = size(matrix, 2);
for i = 1:numberOfRows
for j = 1:numberOfColumns
matrixElement = matrix(i,j);
counter = 0;
for k = 1:numberOfColumns
compareElement = matrix(i,k);
if matrixElement == compareElement
counter = counter + 1;
end
end
msg = strcat('In row number', char(20), num2str(i), char(20), 'Matrix Element', char(20), num2str(matrixElement), char(20), 'is repeated', char(20), num2str(counter), char(20), 'time(s)');
disp(msg);
end
end
10 6 2 1 8
5 3 3 3 5
2 7 4 9 6
3 8 5 1 3
5 3 6 10 5
In row number 1 Matrix Element 10 is repeated 1 time(s)
In row number 1 Matrix Element 6 is repeated 1 time(s)
In row number 1 Matrix Element 2 is repeated 1 time(s)
In row number 1 Matrix Element 1 is repeated 1 time(s)
In row number 1 Matrix Element 8 is repeated 1 time(s)
In row number 2 Matrix Element 5 is repeated 2 time(s)
In row number 2 Matrix Element 3 is repeated 3 time(s)
In row number 2 Matrix Element 3 is repeated 3 time(s)
In row number 2 Matrix Element 3 is repeated 3 time(s)
In row number 2 Matrix Element 5 is repeated 2 time(s)
In row number 3 Matrix Element 2 is repeated 1 time(s)
In row number 3 Matrix Element 7 is repeated 1 time(s)
In row number 3 Matrix Element 4 is repeated 1 time(s)
In row number 3 Matrix Element 9 is repeated 1 time(s)
In row number 3 Matrix Element 6 is repeated 1 time(s)
In row number 4 Matrix Element 3 is repeated 2 time(s)
In row number 4 Matrix Element 8 is repeated 1 time(s)
In row number 4 Matrix Element 5 is repeated 1 time(s)
In row number 4 Matrix Element 1 is repeated 1 time(s)
In row number 4 Matrix Element 3 is repeated 2 time(s)
In row number 5 Matrix Element 5 is repeated 2 time(s)
In row number 5 Matrix Element 3 is repeated 1 time(s)
In row number 5 Matrix Element 6 is repeated 1 time(s)
In row number 5 Matrix Element 10 is repeated 1 time(s)
In row number 5 Matrix Element 5 is repeated 2 time(s)