splitting Excel file into 2 files
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I am wondering how I can split an excel file into 2 new one based on the criteria. say my excel file has 5 columns and 10 rows. I want to check the 5th column and if the number in that column is more than 2300, I want to separate a row completely and put it in one spreadsheet and if it is less than 2300 separate it and put it in another spreadsheet.
can you please advise what I can do? or what is the proper function to do it? ( I have attached a sample file)
0 Commenti
Risposte (1)
Walter Roberson
il 8 Giu 2018
T = readtable('result.csv', 'readvariable', false);
mask = T{:,5} > 2300;
T_high = T(mask,:);
writetable(T_high, 'NewTable.xlsx', 'Sheet', 'high', 'writevariable', false);
T_low = T(~mask, :);
writetable(T_low, 'NewTable.xlsx', 'Sheet', 'low', 'writevariable', false);
3 Commenti
Walter Roberson
il 8 Giu 2018
That would only happen if column 35 was a cell array, such as column 35 was a cell array of character vectors.
... But you said that you have 5 columns... and your example data has 7 columns and the 5th column never exceeds 2300
I should revise what I posted slightly:
T = readtable('result.csv', 'readvariable', false);
mask = T{:,5} > 2300;
T_high = T(mask,:);
if ~isempty(T_high)
writetable(T_high, 'NewTable.xlsx', 'Sheet', 'high', 'writevariable', false);
end
T_low = T(~mask, :);
if ~isempty(T_low)
writetable(T_low, 'NewTable.xlsx', 'Sheet', 'low', 'writevariable', false);
end
as it turns out that writetable errors out if you ask to write an empty table (empty because nothing in column 5 of your sample data exceeds the threshold)
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!