3 d array to 2d array
Show older comments
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 Comment
Mehmed Saad
on 16 Apr 2020
what about t= 3,4,5, ....
Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!