Is it possible to do this without a loop
조회 수: 12 (최근 30일)
이전 댓글 표시
Is it possible to create a vector like this without a loop?

I have only managed v2 with a loop that goes like this:
for k=1:100
v2(k)=cos(k*pi/8)
end
댓글 수: 0
답변 (2개)
Image Analyst
2020년 3월 16일
Try this:
n = 1 : 100
v2 = cos(n * pi / 8)
n = 1 : 30
v3 = n .* exp(n/10)
댓글 수: 0
Arthur Roué
2020년 3월 16일
편집: Arthur Roué
2020년 3월 16일
% The cos function operates element-wise on arrays
v2 = cos((1:100)*pi/8);
댓글 수: 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!