norm calculation using for loop
조회 수: 9 (최근 30일)
이전 댓글 표시
채택된 답변
Adam
2016년 8월 12일
n = norm( x );
does it without a loop. There is no reason to do it with a loop. Even if you don't use norm you would still vectorise is as:
n = sqrt( sum( x.^2 ) );
If you really want a loop the derivation is not difficult though. The vectorised version should certainly be faster, but you can test this yourself.
댓글 수: 4
KL
2017년 10월 16일
As Adam has mentioned in his answer, loop is not necessary but if it's a homework and you must use a loop, then read the documentation to know how it works and then use the for loop iterator to index through the vector.
추가 답변 (0개)
참고 항목
카테고리
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!