It works for me:
for k = 1 : 10
A = randi(9, 8, 1)
[maxValue, linearIndexesOfMaxes] = max(A(:));
[rowsOfMaxes(k), colsOfMaxes] = find(A == maxValue, 1, 'first')
What I suspect is that you're not using 'first', and that may not work. If the max happens at two locations, for example you have 21 twice, then rowsOfMaxes will be two numbers (3 and 6). So you can't stuff two numbers into a single element like rowsOfMaxes(i). Since rowsOfMaxes could have different lengths depending on which iteration you're on and what the values of A happen to be during that iteration, you'll have to have rowsOfMaxes be a cell array, which can handle different sized arrays, unlike a regular numerical array which must be rectanglar.