Copy table's certain data into another table with corresponding variable names
Show older comments
Let's say I have a table with 10 rows and 10 columns. I'd like to copy 5 cols and 10 rows of the table into another one with their variable names. Is there a way to do that?
Thank you.
Accepted Answer
More Answers (1)
Just use normal indexing to get your new table:
demotable = cell2table(num2cell(randi(100, 10, 10)), ...
'VariableNames', ...
arrayfun(@(n) sprintf('Name_%d', n), 1:10, 'uni', 0))
newtable = demotable(:, 3:7)
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!