from what i see, without running it, is that in the freedof(i)=[3i-2 3i-1 3i]; it is trying to assign all 3 3i-2 3i-1 3i] into the index freedof(i) which is 1x1. to get around this you can go
freedof(i,:)=[3i-2 3i-1 3i];
one other thing i see is that you define freedof right before the for loop as a 1x4 matrix. however in the forloop freedof is 1x3. what are you looking for the other number?