table in for loop
1 view (last 30 days)
Show older comments
Reza Hosseini Vedad
on 4 Feb 2021
Commented: Stephen23
on 4 Feb 2021
Hi friends, how can I create multiple tables named as T1, T2, T3, ... and T(n) in a for loop.
for j=1:n
x=rand(5,1);
y=rand(5,1);
T(j)=table(x,y)
end;
0 Comments
Accepted Answer
Stephen23
on 4 Feb 2021
Edited: Stephen23
on 4 Feb 2021
Just use a cell array:
n = 5;
C = cell(1,n);
for j=1:n
x=rand(5,1);
y=rand(5,1);
C{k} = table(x,y);
end
Note that using one table is likely to be a better approach:
2 Comments
Stephen23
on 4 Feb 2021
"now I need all rows of this cells in a single table, what can I do?"
You can concatenate the contents of the cell array, e.g.:
T = vertcat(C{:});
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!