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

56 views (last 30 days)
Pavel Kuzmitsky
Pavel Kuzmitsky on 28 Oct 2020
Commented: Pavel Kuzmitsky on 1 Nov 2020
как извлечь из цикла все выходные данные в виде векторного массива?
например:
for n=1:3
y=2*n;
end
хочу получить после завершения цикла массив x=[2 4 6] но непонимаю как

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Manage Products in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!