How to use for loop structure to calculate two vectors to dot product
조회 수: 48 (최근 30일)
이전 댓글 표시
How to use for loop structure to calculate two vectors to dot product.
Please give an example.
댓글 수: 0
답변 (1개)
William
2021년 2월 20일
a = 1:5;
b = 6:10;
c = 0;
for j = 1:5
c = c + a(j)*b(j);
end
However, this calculation can be done more simply with the dot() function:
c = dot(a,b);
or with the expression:
c = sum(a.*b);
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!