how to solve this error horzcat Dimensions of matrices being concatenated are not consistent?

1 visualización (últimos 30 días)
hi all, how can i solve this problem
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in (line 131)
temp3=max([U3 u3max]);
in this code?
u1max=0; u2max=0; u3max=1;
for i=1:N-1
j=N-i;
y=[g1(j+1) g2(j+1) g3(j+1) g4(j+1) g5(j+1) g6(j+1)];
k1=h*costate(y,A1,A2,A3,S(j+1),I(j+1),C(j+1),B(j+1),u1(j+1),u2(j+1),u3(j+1),mu_h,beta_1,beta_2,phi,K,delta,q,d1,eta_1,epsilon_1,alpha,eta_2,l,epsilon_2,omega,r,mu_b,sigma,K_p);
k2=h*costate(y-0.5*k1,A1,A2,A3,S(j+1),I(j+1),C(j+1),B(j+1),u1(j+1),u2(j+1),u3(j+1),mu_h,beta_1,beta_2,phi,K,delta,q,d1,eta_1,epsilon_1,alpha,eta_2,l,epsilon_2,omega,r,mu_b,sigma,K_p);
k3=h*costate(y-0.5*k2,A1,A2,A3,S(j+1),I(j+1),C(j+1),B(j+1),u1(j+1),u2(j+1),u3(j+1),mu_h,beta_1,beta_2,phi,K,delta,q,d1,eta_1,epsilon_1,alpha,eta_2,l,epsilon_2,omega,r,mu_b,sigma,K_p);
k4=h*costate(y-k3,A1,A2,A3,S(j+1),I(j+1),C(j+1),B(j+1),u1(j+1),u2(j+1),u3(j+1),mu_h,beta_1,beta_2,phi,K,delta,q,d1,eta_1,epsilon_1,alpha,eta_2,l,epsilon_2,omega,r,mu_b,sigma,K_p);
y=y-(1/6)*(k1+2*k2+2*k3+k4);
g1(j)=y(1); g2(j)=y(2); g3(j)=y(3); g4(j)=y(4); g5(j)=y(5); g6(j)=y(6);
w=((beta_1*I)+((beta_2*C)+(phi*B)/(K+B)));
U1=((eta_1*g3(j)*I(j))+(eta_2*C(j)*g4(j))-(((eta_1*I(j))+(eta_2*C(j)))*g5(j)))/P1;
U2=(sigma*B(j)*g6(j))/P2;
U3=(((w+mu_h)*g2(j)*S(j))-((w+mu_h)*g1(j)*S(j))+((epsilon_1*I(j))+(epsilon_2*C(j)))*g6(j))/P3;
temp1=min([U1 u1max]);
u1(j)=max([0 temp1]);
temp2=min([U2 u2max]);
u2(j)=max([0 temp2]);
temp3=max([U3 u3max]);
u3(j)=min([0 temp3]);
end
ps. i am new in matlab.
Cheers!
  2 comentarios
KSSV
KSSV el 14 de Mayo de 2021
temp3=max([U3 u3max]);
Check the dimensions of U3 and u3max...they should be row vectors to join them....it seems they are not in your case.

Iniciar sesión para comentar.

Respuesta aceptada

KSSV
KSSV el 15 de Mayo de 2021
You can get the dimension using the function size. In your case one is row vector and other is column vector so you are getting error.
Example:
A = [1 2] ;
B = [3 ;4] ;
AB = [A B]
Error using horzcat
Dimensions of arrays being concatenated are not consistent.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by