3 d array to 2d array

1 Ansicht (letzte 30 Tage)
Nur Amalina
Nur Amalina am 16 Apr. 2020
Kommentiert: Mehmed Saad am 16 Apr. 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 Kommentar
Mehmed Saad
Mehmed Saad am 16 Apr. 2020
what about t= 3,4,5, ....

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by