How do I multiply two variables of form A(:,:, i) and B(:,:,i) where i = 20
조회 수: 2 (최근 30일)
이전 댓글 표시
SO basically , I need the product of these 2 variables for 20 iterations and then add the products. I tried using * and .* but that doesn't work.
댓글 수: 3
Jan
2018년 3월 20일
In this formula you multiply with the squared norm of Phi, which is a scalar, not a matrix.
채택된 답변
Prajit T R
2018년 3월 19일
Hi Sagar
Try this code:
sum=0
for i=1:20
sum=sum+s(:,:,i).*(phi(:,:,i).^2)
end
It will work if the sizes of A and B match.
Cheers
댓글 수: 1
Jan
2018년 3월 20일
Using "sum" as variable causes troubles frequently, because the builtin function sum() is not available afterwards. Better avoid shadowing of builtin functions by using different names.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!