Matrix multiplication error in matlab. Error: Matrix dimensions must agree : I keep getting the error matrix dimensions must agree. In the line 
    	next_state1 = (p01<alphadt) .* (state==0);
I've tried changing the multiplication to just * with no improvement. What I've looked up [online][1] hasn't seemed to be able to help me. I don't understand matlab very well so you will have to be very specific in your explanation.

**Error**

    Matrix dimensions must agree.
    
    Error in q3>next_state (line 59)
    	next_state1 = (p01<alphadt) .* (state==0);
    
    Error in q3>timeloop (line 49)
    		st(i+1,1:4) = next_state(st(i,1:4),a,B,1e-4);
    
    Error in q3 (line 4)
    	m = timeloop(a,B);
    
    Error in run (line 86)
    evalin('caller', [script ';']);

**Code**

    function main()
            a = [0.0050,0.0109,0.0224];
            B = [1.2151,0.6972,0.4000];
            m = timeloop(a,B);
    end

    function m = timeloop(a,B)
            st = zeros(49,4);
            t = 0:0.001:0.05;
            for i = (1:49)
                    st(i+1,1:4) = next_state(st(i,1:4),a,B,1e-4);
            end 
            m = mean(prod(state,2))
    end
    
    function next_state = next_state(state,alpha,beta,dt)
            nch = size(state,2);
            p01 = rand(1,nch);
            alphadt = repmat(alpha,1,nch)*dt;
            betadt = repmat(beta,1,nch)*dt;
            next_state1 = (p01<alphadt) .* (state==0);
            next_state0 = (p01<betadt) .* (state==1);
            next_state = state + next_state1 - next_state0;
    end


  [1]: https://se.mathworks.com/matlabcentral/answers/322080-how-can-i-fix-this-error-error-using-matrix-dimensions-must-agree