フィルターのクリア

deleting unneeded columns from tables after using them

3 ビュー (過去 30 日間)
Salma fathi
Salma fathi 2021 年 9 月 28 日
コメント済み: Salma fathi 2021 年 10 月 12 日
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:
  1. how can we get rid of the fisrt five columns (year,month,day,hour,minute) after getting the Date value from them?
  2. 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?

採用された回答

Kevin Holly
Kevin Holly 2021 年 9 月 28 日
1.
t.YEAR = [];
t.MONTH = [];
t.DAY = [];
t.HOUR = [];
t.MIN = [];
2.
struct.date = t.Date(1);
t.Date = [];
struct.table = t
  2 件のコメント
Siddharth Bhutiya
Siddharth Bhutiya 2021 年 9 月 30 日
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.
Salma fathi
Salma fathi 2021 年 10 月 12 日
Thank you @Kevin Holly and @Siddharth Bhutiya, That was very very helpful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by