Split a Table into two tables
83 views (last 30 days)
Show older comments
I have a table H, that is approximately 68,000 lines long, im trying to export it to a .xls file but it is to large, im trying to figure out how to split this table into two tables so that i can export it.
3 Comments
Voss
on 19 Oct 2023
You can use one of the approaches given in answers to your previous question:
Answers (1)
Pratyush
on 20 Oct 2023
Hi Jacob,
I understand that you want to split your table into 2 equal parts and export them to two different XLS file. You can use indexing for this. Here's an example of how you can split the table into two equal-sized tables:
% Assuming your table is named 'H'
% Determine the number of rows in the table
numRows = size(H, 1);
% Split the table into two equal-sized tables
splitIndex = floor(numRows / 2);
table1 = H(1:splitIndex, :);
table2 = H(splitIndex+1:end, :);
% Export table1 to Excel
writetable(table1, 'table1.xls');
% Export table2 to Excel
writetable(table2, 'table2.xls');
If you encounter memory issues while exporting large tables, you can consider exporting the tables to CSV format instead of Excel. CSV files have a higher size limit and can be easily opened in Excel. To export as CSV, replace the file extension in the 'writetable' function with '.csv'.
2 Comments
Walter Roberson
on 20 Oct 2023
It is misleading to say that CSV files have a higher size limit and can be easily opened in Excel.
When you try to import a CSV file into Excel and the CSV file has more rows than is supported by Excel (limit is 2^20 - 1 = 1048575 ) then Excel will either give an error or else drop the extra rows.
You can create indefinitely long csv files, as they are just text files and so are limited only by the maximum file size for your file system (and the amount of space you have available.) However if you have more rows of csv than the longest supported xlsx file, then Excel will not be able to handle the large csv file... you would need to use some other software.
Stephen23
on 20 Oct 2023
As well as the point raised by Walter Roberson, it is worth noting that when importing text files (e.g. CSV) MS Excel can and does modify data without warning. That loss of data is irreversible and is often unnoticed by the user until later in their data processing. MS Excel is an unreliable tool for processing text file data.
Depending on the user requirements, XLSX is most likely a better file format than XLS.
See Also
Categories
Find more on Spreadsheets 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!