MATLAB: How to get one table instead of multiple tables.

arraystables

this is my code
for i=1:100
num = randi([1 75], 1, 5);
ex_num = randi([1 15], 1 , 1);
x=sort(num);
s = horzcat(x, ex_num);
table(i,s(1),s(2),s(3),s(4),s(5),s(6),'VariableNames', {'iter' 'first' 'second' 'third' 'fourth' 'fifth' 'extra'}, 'RowNames' ,{'iteration'})
end
for i=1:100 num = randi([1 75], 1, 5); ex_num = randi([1 15], 1 , 1); x=sort(num); s = horzcat(x, ex_num); table(i,s(1),s(2),s(3),s(4),s(5),s(6),'VariableNames', {'iter' 'first' 'second' 'third' 'fourth' 'fifth' 'extra'}, 'RowNames' ,{'iteration'}) end
Once I run the code I get what I want, however, I get 100 separate tables instead just getting one continuous table.

Best Answer

you have two methods, to either add to the table instead of creating a new table or create the table at the end and build a matrix storing all the data.
for i=1:5
num = randi([1 75], 1, 5);
ex_num = randi([1 15], 1 , 1);
x=sort(num);
iteration(i,1)=i;
s = horzcat(x, ex_num);
S(i,:) = horzcat(x, ex_num);
T(i,:)=table(i,s(1),s(2),s(3),s(4),s(5),s(6),'VariableNames', {'iter' 'first' 'second' 'third' 'fourth' 'fifth' 'extra'}, 'RowNames' ,{'iteration'});
end
table(iteration,S(:,1),S(:,2),S(:,3),S(:,4),S(:,5),S(:,6),'VariableNames', {'iteration' 'first' 'second' 'third' 'fourth' 'fifth' 'extra'})
so in the sample code i added two methods. 1 is to create the table variable T which appends to the existing table instead of generating a new table.
The other is the last line and the S(i,:) which generates the table at the end. you cannot have duplicate row names so i removed your iteration label for each row. additionally you've already labeled it in column 1.