MATLAB Answers

summation inside for loop

1 view (last 30 days)
Mert Demir
Mert Demir on 21 Jul 2021
Edited: VBBV on 25 Jul 2021
Have a good day. I am trying to find an easy way of writing a loop below:
v_e=ones(100,5)
for iz=1:5
for iznext=1 exp2(:,iz)=v_e(:,iznext)*Q_z(iz,iznext)+v_e(:,iznext+1)*Q_z(iz,iznext+1)+v_e(:,iznext+2)*Q_z(iz,iznext+2)+v_e(:,iznext+3)*Q_z(iz,iznext+3)+v_e(:,iznext+4)*Q_z(iz,iznext+4);
end
end
Q_z is 5*5 transition matrix
Thanks in advance. I did this as a dot product but i am looking smt that can be done using loop.

Answers (2)

VBBV
VBBV on 21 Jul 2021
%if true
for iznext=1:5
Change this line. Since you said Q_z is 5x5 transition matrix
  3 Comments
VBBV
VBBV on 25 Jul 2021
%if true
exp2=zeros(100,5,5)
for iz=1:5
for iznext=1:5 exp2(:,iz,iznext)=exp2(:,iz,iznext)+v_e(:,iznext)*Q_z(iz,iznext);
end
end
You can try this by making v_e as 100x5x5

Sign in to comment.


Torsten
Torsten on 21 Jul 2021
vec = ones(1,5)*Q_z.' ;
exp2(1:100,:) = vec ;
  1 Comment
Mert Demir
Mert Demir on 21 Jul 2021
Thanks but i need to use v_e in the form. v_e will not be ones(100,5) later on. it is just an initial guess. I will keep iterate that.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!