Your state matrix should be in a MATLAB for loop that runs once each trial:
for currentTrial = 1:MaxTrials
% Create a state matrix
% Send and run state matrix
end
You can then use MATLAB's rand() function to randomize an interval:
for currentTrial = 1:MaxTrials
thisInterval = rand*(largestInterval);
% Create a state matrix using thisInterval as the timer for one of the states
% Send and run state matrix
end
I hope this helps!