Efficient multiplication between arrays without for loops
古いコメントを表示
I have two arrays which need to be multiplied across individual elements of all rows and columns. This is simply achieved through the .* operator. However, in my scenario, both arrays I possess are three dimensional and my operation using for loops proceed as follows,
mass = 80;
for t=1:size(Vel,3)
for branch=1:size(Eigen,3)
Velocity=Vel(:,:,t);
Eig=Eigen(:,:,branch);
Q=Velocity.*conj(Eig).*((mass)^0.5);
Q_direction=sum(Q,2);
Q_atom=sum(Q_direction,1);
Q_branch(branch)=Q_atom;
end
Q_dot(t,:)=Q_branch;
end
Where I take the t(th) dimension of array 'Vel' and the branch(th) dimension of array 'Eigen' into two 2D arrays, and perform the multiplication between individual elements. However, I need to do the same process across all of the 3rd dimensions in both 'Vel' and 'Eigen' arrays. Is there a more efficient way to complete this without using for loops?
Note: Once the multiplication is obtained, the columns and rows of the arrays are summed. The data to be stored are based on the 3rd dimension of Array 'Vel' and 3rd dimension of Array 'Eigen' (Output is dependent only on t and branch).
Also let me know if the efficiency of this section can be improved in any other way. I am new to matlab and any sort of programming language, so thanks in advance for any support.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!