Adding new table data to an existing table (while loop)

I have a 16x1 table (or array) of data that is calculated during each loop iteration. However, I would like to simply add a new 16x1 column to this same table 'A', with the new calculated data in the next column of said table, for N times of the loop. Today, the iteration overwrites the table. What is desired, is if I run the loop 250 times, it would look like a 16x250 table. For example:
i=0;
N=250;
while i < N
//do my 16 variable calculations
//store data in 16xN table/array
i=i+1
end

1 Comment

To help clarify the type of table I am using, it looks like:
A=[x1;x2;x3....;x16];

Sign in to comment.

Answers (1)

A(end+1,:) = new vector of 16 values
Note: it is much more efficient to pre-allocate the array and write into the appropriate column.
A = zeros(16, N);
for i = 1 : N
A(:,i) = .....
end

Categories

Asked:

on 15 May 2015

Answered:

on 15 May 2015

Community Treasure Hunt

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

Start Hunting!