As usual for this error message (or at least what I guess the error message is): The debugger help to find the problem:
Then run the code again until it stops, when the problem occurs. Then inspect the dimensions of the locally used variables. Perhaps duplicatematrices has less than 95 elements, or the contents of duplicatematrices{i} has less than 2 columns, or availmat has less than 95 elements? Are you sure that t has the required number of ba{i}(jj) elements?
It is easier, when you try to find answers for these questions by your own.
What you will find out in less than a minute:
For i==11, j==2, t has 14 elements only, but ba{11}(2) is 15. Therefore t(1:ba{i}(jj)) cannot work.
I cannot suggest an improvement, because all I see is the not working code, while I cannot guess its intention. It is like "I have a+b=17, but I want another result" - impossible in theory to guess what the user needs.
Best Answer