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

135 vues (au cours des 30 derniers jours)
Pavel Kuzmitsky
Pavel Kuzmitsky le 28 Oct 2020
как извлечь из цикла все выходные данные в виде векторного массива?
например:
for n=1:3
y=2*n;
end
хочу получить после завершения цикла массив x=[2 4 6] но непонимаю как

Réponse acceptée

madhan ravi
madhan ravi le 28 Oct 2020
n = 1 : 3;
for k = 1 : numel(n)
y(k) = 2*n(k);
end
  3 commentaires
madhan ravi
madhan ravi le 29 Oct 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 le 1 Nov 2020
спасибо

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by