> " How to debug error... "
That's the right question to ask (+1).
Knowing that there would be an error, I started by setting the pause on errors (image below).
It paused on this line below where I evaluated i and j to find that the error occurs on the first iteration of both loops.
And then I saw it 👀 data{i,j}(4,1)
data{i,j} or data{1,1} accesses the first element of the data cell array, [4 10]. Notice that this has 1 row and 2 columns but you're asking for row 4, column 1. Hence the error, "Index in position 1 exceeds array bounds".
That error would also occur in the second condition, data{1,3} since none of the cell elements contain 3 rows. Rather than guessing what your intensions are, if you describe the goal I could help get you there.