How do I save the output from a for loop to an array?
Show older comments
clc;
clear;
%user enters the number of loops
a=input('Enter the number of loops in the system: ');
b=(1:a);
i=transpose(b);
%user enters the number of lines in each loop
%How do I get the the outputs from the for loop to be saved to an array that I can call later in the program?
for c=1:a;
d=input(['Enter the number if lines in loop ', num2str(c),': ']);
end
Answers (1)
Voss
on 22 Jun 2022
d = zeros(a,1);
for c = 1:a
d(c) = input(['Enter the number of lines in loop ', num2str(c),': ']);
end
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!