I have an array of matrices which are all different lengths. I want to compare the distance of each item in matrix 1 to the items in matrix 2 and so on. The for loops I've written below work well except when it reaches a matrix which is length 2. The loop continues to xx = 3 and then calls an error ("Index in position 1 exceeds array bounds. Index must not exceed 2.") because there is no current_mat(3,:). Why is it doing this only for matrices of length 2? I'm relatively new to matlab, so apologies if this is a simple question. Here are some toy data that give the same error I am seeing with a larger dataset.
matrix_1 = ones(16,3)
matrix_2 = ones(14,3)
matrix_3 = ones(2,3)
matrix_4 = ones(10,3)
my_array = {matrix_1; matrix_2; matrix_3; matrix_4}
for ii = 1:length(my_array)-1;
current_mat = my_array{ii};
compare_mat = my_array{ii+1};
for xx = 1:length(current_mat);
xx_info = current_mat(xx,:);
end
end