Info

This question is closed. Reopen it to edit or answer.

How can I input the answers that shoot out of a loop into a vector?

1 view (last 30 days)
For example
while i < 2
integral (function, 0, i)
I want the answers to be input into a vector.

Answers (1)

Geoff Hayes
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.

Tags

Products

Community Treasure Hunt

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

Start Hunting!