MATLAB: Plot system of ODE in 22 variables.

MATLABodeode45

I am trying to plot a system of ODE with 22 variables using ode45 using this code:
dydt=@(t,x)[-(k1*x(2)*x(1)-r1*x(3));-(k1*x(2)*x(1)-r1*x(3));(k1*x(2)*x(1)-r1*x(3))- 2*(k2*x(3)*x(3)-r2*x(4));(k2*x(3)*x(3)-r2*x(4)) + (V4*x(5)/(K4+x(5))) - (k3*x(4)-r3*x(5));(k3*x(4)-r3*x(5)) + (k7*x(7)-r7*x(5)*x(18)) + (k11*x(9)-r11*x(5)*x(14)) + (k15*x(11)-r15*x(15)*x(5)) + (k18*x(12)-r18*x(5)*x(16)) + (k20*x(13)-r20*x(13)*x(5)) -(V4*x(5)/(K4+x(5)))-(k5*x(5)*x(17)-r5*x(6)) - (k9*x(5)*x(20)-r9*x(8)) - (k13*x(5)*x(21)-r13*x(10));(k5*x(5)*x(17)-r5*x(6))- (k6*x(6)-r6*x(7));(k6*x(6)-r6*x(7))- (k7*x(7)-r7*x(5)*x(18));(k9*x(5)*x(20)-r9*x(8)) - (k10*x(8)*x(22)- r10*x(9));(k10*x(8)*x(22)- r10*x(9)) - (k11*x(9)-r11*x(5)*x(14));(k13*x(5)*x(21)-r13*x(10)) - (k14*x(10)-r14*x(11));(k14*x(10)-r14*x(11))- (k24*x(11)*x(14)-r24*x(13));(k17*x(11)*x(20)-r17*x(12))- (k18*x(12)-r18*x(5)*x(16)) - (k19*x(12)*x(22)-r19*x(13));(k19*x(12)*x(22)-r19*x(13)) - (k20*x(13)-r20*x(13)*x(5)) + (k24*x(11)*x(14)-r24*x(13));(k11*x(9)-r11*x(5)*x(14)) + (k23*x(13)-r23*x(15)*x(14)) - (k12*x(14)-r12*x(20)*x(22))- (k24*x(11)*x(14)-r24*x(13));(k15*x(11)-r15*x(15)*x(5)) + (k23*x(13)-r23*x(15)*x(14)) - (k21*x(15)*x(20)-r21*x(16)) - (V16*x(15)/(K16+x(15)));(k18*x(12)-r18*x(5)*x(16)) + (k21*x(15)*x(20)-r21*x(16)) - (k22*x(22)*x(16)-r22*x(13));(V8*x(18)/(K8+x(18))) - (k5*x(5)*x(17)-r5*x(6));(k7*x(7)-r7*x(5)*x(18))- (V8*x(18)/(K8+x(18))) - (k25*x(18)-r25*x(19));(k25*x(18)-r25*x(19));(k12*x(14)-r12*x(20)*x(22))-(k9*x(5)*x(20)-r9*x(8))-(k17*x(11)*x(20)-r17*x(12))- (k21*x(15)*x(20)-r21*x(16));(V16*x(15)/(K16+x(15)))- (k13*x(5)*x(21)-r13*x(10));(k12*x(14)-r12*x(20)*x(22)) - (k19*x(12)*x(22)-r19*x(13)) - (k10*x(8)*x(22)- r10*x(9)) - (k22*x(22)*x(16)-r22*x(13))];
y0 = [cond1; cond2;cond3;cond4;cond5;cond6;cond7;cond8;cond9;cond10;cond11;cond12;cond13;cond14;cond15;cond16;cond17;cond18;cond19;cond20;cond21;cond22];
tspan = [0, 125];
ode45(dydt,tspan,y0);
But unfortunately I am getting an error: Error using vertcat Dimensions of matrices being concatenated are not consistent.

Best Answer

The spaces in the individual rows are most likely causing the problem, for example in:
...; (k1*x(2)*x(1)-r1*x(3))- 2*(k2*x(3)*x(3)-r2*x(4)); ...
Either eliminate them:
...; (k1*x(2)*x(1)-r1*x(3))-2*(k2*x(3)*x(3)-r2*x(4)); ...
or put the entire row in parentheses so that MATLAB considers this one expression:
...; ( (k1*x(2)*x(1)-r1*x(3))- 2*(k2*x(3)*x(3)-r2*x(4)) ); ...
That should work, at least to eliminate that error.
I cannot run your code.