First, I am glad that although you are asking for help on homework you have made a good attempt on your own and are now just struggling with some MATLAB issues. That's a good point to come to MATLAB answers for help.
You have a few problems.
First you want all of your accelerations to be 1D vectors. You are assigning some of them to be matrices for example:
creates a 10 row by length(t2) number of columns matrix. You want that first argument to just be 1 so that you make a row vector. (or you could use ones(length(t2),1) and make it a column vector, but you'd have to be consistent through out so the time vectors should then also be columns)
Next your accelerations magnitudes are not correct. Of course acceleration is change in velocity per unit time. So the first segment the acceleration is 10m/s/(10s) = 1m/s^2, The second segement it is zero, etc
Finally when you create the overall solution you have to consider the initial condition for the velocity. The way you are doing it you are calculating it as if you are starting at zero velocity for each segment. Of course the start velocity of the second segment is the end velocity of the first segment, etc.
So you could use something like
v2 = v1(end) + cumtrapz(a2)*dt
.and something similar for the final segment.
Hope this helps.
Note to format your code nicely you can use the code button in the MATLAB answers toolbar.