deleting unneeded columns from tables after using them
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Salma fathi
le 28 Sep 2021
Commenté : Salma fathi
le 12 Oct 2021
I need one little help in the follwoing:
the code I attached is supposed to read some files as tables. split a table into smaller tables according to some criteria and store them in a cell array. Now for each table in the cell array we are concerned only with having the two columns of the variables (GDALT and NE8) from a data file, but we also would like to use the fisrt five columns (year,month,day,hour,minute) to generate a date of a table so we can use that to refer to it or search for it in the future.
The attached code is baisically raeding the (GDALT and NE8) columns that we are intreseted in. raed the other five columns (year,month,day,hour,minute) and combines them to have the Date variable added to the table. But this is not effecient because after we have the Date value we don't need the other 5 columns and having them permenentaly would be a waste of storage also, for a specific table the Date value is the same for all the rows so having it for each and every row in the table again would be a waste of storage. So my question comes down to this:
- how can we get rid of the fisrt five columns (year,month,day,hour,minute) after getting the Date value from them?
- would it be possible to store the date value for a table, outside that tables for ex(in the cell next to it in the second column of the cell array), instead of having it for each row in the table?
0 commentaires
Réponse acceptée
Kevin Holly
le 28 Sep 2021
1.
t.YEAR = [];
t.MONTH = [];
t.DAY = [];
t.HOUR = [];
t.MIN = [];
2.
struct.date = t.Date(1);
t.Date = [];
struct.table = t
2 commentaires
Siddharth Bhutiya
le 30 Sep 2021
You could do the deletion in one call.
t(:,{'YEAR','MONTH','DAY','HOUR','MIN'}) = []
Also if the variables are always the first five then you can use numeric indices as well
t(:,1:5) = []
For the second question, Kevin has already mentioned one way of doing this. Another way would be to store that as a big timetable of cell array of tables.
dates = t.Date;
t.Date = [];
tt = timetable;
tt.DataTable(dates(1)) = {t};
tt.DataTable(dates(2)) = {t};
tt.DataTable(dates(3)) = {t}
tt =
3×1 timetable
Time DataTable
____________________ ___________
01-Oct-2021 11:26:11 {2×2 table}
02-Oct-2021 11:26:11 {2×2 table}
03-Oct-2021 11:26:11 {2×2 table}
Since you mentioned you might want to search for tables for certain dates, storing this as a timetable shown above would allow you to index into this using dates and would making searching and filtering based on dates easy.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!