Is it possible to do this without a loop

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

Antworten (2)

Image Analyst
Image Analyst am 16 Mär. 2020

1 Stimme

Try this:
n = 1 : 100
v2 = cos(n * pi / 8)
n = 1 : 30
v3 = n .* exp(n/10)
Arthur Roué
Arthur Roué am 16 Mär. 2020
Bearbeitet: Arthur Roué am 16 Mär. 2020

0 Stimmen

% The cos function operates element-wise on arrays
v2 = cos((1:100)*pi/8);

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 16 Mär. 2020

Beantwortet:

am 16 Mär. 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by