MATLAB Answers

How do i save values for each iteration ?

18 views (last 30 days)
Lauris Cuzans
Lauris Cuzans on 16 Apr 2021 at 13:32
Answered: David Hill on 16 Apr 2021 at 13:39
clc
clear
for a = [0.01 0.01 0.01 0.03 0.1 0.2 0.3 0.3 0.3 0.4 0.4 0.4 0.3 0.4 0.5 0.8 0.9 1 0.8 0.7 0.5 0.2 0.1 0.03];
b=a*5
end
How can I store new values of b for each iteration ?
  1 Comment
Mischa Kim
Mischa Kim on 16 Apr 2021 at 13:36
Hi Lauris, depends. What exactly are you trying to do?

Sign in to comment.

Accepted Answer

David Hill
David Hill on 16 Apr 2021 at 13:39
a = [0.01 0.01 0.01 0.03 0.1 0.2 0.3 0.3 0.3 0.4 0.4 0.4 0.3 0.4 0.5 0.8 0.9 1 0.8 0.7 0.5 0.2 0.1 0.03];
for k= 1:length(a)
b(k)=a(k)*5;%index into b
end
Better, just multiply, no loop needed.
b=5*a;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by