Is it possible to do this without a loop

9 visualizaciones (últimos 30 días)
Olaf Zbierzchowski
Olaf Zbierzchowski el 16 de Mzo. de 2020
Respondida: Image Analyst el 16 de Mzo. de 2020
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

Respuestas (2)

Image Analyst
Image Analyst el 16 de Mzo. de 2020
Try this:
n = 1 : 100
v2 = cos(n * pi / 8)
n = 1 : 30
v3 = n .* exp(n/10)

Arthur Roué
Arthur Roué el 16 de Mzo. de 2020
Editada: Arthur Roué el 16 de Mzo. de 2020
% The cos function operates element-wise on arrays
v2 = cos((1:100)*pi/8);

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by