3 d array to 2d array

1 次查看(过去 30 天)
Nur Amalina
Nur Amalina 2020-4-16
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!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by