3 d array to 2d array

1 visualización (últimos 30 días)
Nur Amalina
Nur Amalina el 16 de Abr. de 2020
Comentada: Mehmed Saad el 16 de Abr. de 2020
Hi All!
I am trying to fix this code
e = [0 1 0 1;1 0 1 1;0 1 0 1;1 1 1 0];
x = [0;0;0;0;0;0];
a1=2;
a2=4;
for t = 2:100
x(:,2)=[1;2;3;4;5;6];
for i=1:6
for j=1:6
u(i,j,t)=a1*e(i,j)*(x(j,t)-x(i,t))+a2*(x(i,t)-x(i,t-1));
end
end
u=sum(u,2);
u=permute(u,[1 3 2]);
end
I keep getting error warning like this "u(i,j,t) Index in position 2 exceeds array bounds (must not exceed 2)." I think the problem is in the initial x. what i want is when t = 1, x = [0;0;0;0;0;0]; and when t is 2 x=[1;2;3;4;5;6]; and the solution can give me u (i,t)
May anyone help me? thanks in advance!
  1 comentario
Mehmed Saad
Mehmed Saad el 16 de Abr. de 2020
what about t= 3,4,5, ....

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by