Hi all;
I have a matrix named "a" which must be multiplied by 4 different numbers for each index of "i". I want to do this without inner for loop "j".
For example like program below,for ' i=1' and 'j=1' , all elements of matrix ' a' must be multiplied by 'pr(1,1)'. This operation would be repeated up to 'j=4'. I want to omit 'j loop' in the way for each 'i' , all elements of 'a' multiplied by all columns of 'pr(i,:)' without for loop 'j'. In your opinion, how can I do this? This example was described below:
pr=[0.3 0.5 0.1 0.1; 0.2 0.5 0.2 0.1; 0.3 0.4 0.2 0.1;0.2 0.4 0.1 0.3]; a=[3,7,0,5,8;9,3,1,0,0;3,2,9,2,0;1,4,9,3,1;];
sum=0; for i=1:4 for j=1:4 sum = sum + pr(i,j)*a; end end
Thaks,
Best Answer