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

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

Answers (1)

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.

This question is closed.

Products

Tags

Asked:

on 19 Apr 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!