How can I input the answers that shoot out of a loop into a vector?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
For example
while i < 2
integral (function, 0, i)
I want the answers to be input into a vector.
Answers (1)
Geoff Hayes
on 19 Apr 2015
Felipe - pre-size a matrix to store this data before entering the while loop (or use a for loop instead). If we assume that the calculate integral at each iteration of the loop is a scalar value then we can do the following
maxUpperLimit = 2;
calcIntegral = zeros(maxUpperLimit,1);
for k = 1:maxUpperLimit
calcIntegral(k) = integral (function, 0, k);
end
The above will calculate the integral for the upper limits of 1 and 2. You should be able to adapt this to suit your needs.
1 Comment
Felipe Nunez
on 19 Apr 2015
This question is closed.
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!