How can I extract and then write data in certain order from other excel files to excel file?
1 view (last 30 days)
Show older comments
My excel workbook inserts seven worksheets. A,B and C columns in every worksheets are same. Next five columns are respectively values of longitude 25, 30, 35, 40 and 45 related to sheets(Lat30, Lat32.5 and so on). My data is normally 99888x8 table. Small data example orders as Data.xlsx file and I would like to do as Test.xlsx file.
A column: Year (from 1998 to 2017)
B column: Day of the year (from 1 to 365 or 366)
C column: Hour
D,E,F,G & H columns: TEC values
I'd like to write like test.xlsx file for every hour but I have no idea how I write like Test.xlsx file for every hour?
0 Comments
Accepted Answer
Guillaume
on 15 Mar 2019
Edited: Guillaume
on 15 Mar 2019
[~, sheets] = xlsfinfo('Data.xlsx'); %get list of sheets
lattables = cell(size(sheets)); %preallocate cell array of table
for sh = 1:numel(sheets)
latitude = sscanf(strrep(sheets{sh}, '_', '.'), 'Lat%f'); %extract latitude from sheet name (replace _ by . so that Lat is followed by an actual number
lattables{sh} = readtable('Data.xlsx', 'Sheet', sheets{sh}); %read sheet
lattables{sh}.Latitude = repmat(latitude, height(lattables{sh}), 1); %append latitude column (all identical for the current table)
end
fulltable = vertcat(lattables{:}); %once all are loaded, concatenate into a single table
fulltable = stack(fulltable, 4:8, 'ConstantVariables', [1:3, 9], 'NewDataVariableName', 'TEC', 'IndexVariableName', 'Longitude');
fulltable.Longitude = sscanf(strrep(strjoin(cellstr(fulltable.Longitude)), '_', '.'), 'Long%f ')
0 Comments
More Answers (1)
Suat YAZICI
on 16 Mar 2019
1 Comment
Guillaume
on 17 Mar 2019
With more than 3 million rows, you wouldn't be able to copy ir into excel as Excel is limited to 1,048,576 rows.
You could write it into a text file, it may take a while:
writetable(fulltable, 'C:\somewhere\somefile.txt');
Otherwise you need to reduce the size of the table. Maybe split it into yearly tables (this can be done easily with splitapply).
Note that if your tables are less than a million row, you can export them into an excel file without copy/pasting, using writetable.
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!