MATLAB: Using loop to create multiple variables

for loop

Say I wanted to create 16 variables: x1, x2, … x16. Each x variable is equal to b1, b2, … b16 * some scalar A. Could I use a for loop to accomplish this task? I was thinking along the lines of:
for i = 1:1:16
x_i = b_i * A
i = i+1
end
But this won't work.

Best Answer

you can try this:
%b is a vector contains values from 1,2,3....to 16.
b = 1:16;
A=2; % A is a scalr whose value is 2
for i = 1:1:16
x(i) = b(i) * A;
i = i+1;
end
Related Question