как получить векторный массив выходных данных цикла for

153 visualizaciones (últimos 30 días)
Pavel Kuzmitsky
Pavel Kuzmitsky el 28 de Oct. de 2020
Comentada: Pavel Kuzmitsky el 1 de Nov. de 2020
как извлечь из цикла все выходные данные в виде векторного массива?
например:
for n=1:3
y=2*n;
end
хочу получить после завершения цикла массив x=[2 4 6] но непонимаю как

Respuesta aceptada

madhan ravi
madhan ravi el 28 de Oct. de 2020
n = 1 : 3;
for k = 1 : numel(n)
y(k) = 2*n(k);
end
  3 comentarios
madhan ravi
madhan ravi el 29 de Oct. de 2020
You definitely didn't understand properly, anyway you don't need a loop:
k = 3;
v = -2 : 2;
R = sum(v( : ) .^ ( 0 : k), 2)
R = 5×1
-5 0 1 4 15
Pavel Kuzmitsky
Pavel Kuzmitsky el 1 de Nov. de 2020
спасибо

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by