store changing value sequentially in an array in a loop in matlab

You can create a vector with a fixed size before the loop starts and fill it iteratively within the loop. Here is an example code snippet:

main.m
% Define the vector with a fixed size
myVector = zeros(1, n);

% Loop over iterations and fill the vector
for i = 1:n
    % Calculate the changing value in your loop
    currentValue = i^2 + 3*i;
    % Store the value in the vector
    myVector(i) = currentValue;
end
268 chars
11 lines

In this example, n specifies the number of iterations you want to perform. The loop calculates some changing value at each iteration and stores it into the myVector array. After the loop finishes, the myVector array will contain n values that were generated during the iterations.

related categories

gistlibby LogSnag