Create table from an other table
Mostrar comentarios más antiguos
Hello everyone,
I created 33 tables containing 3 row with date (from 2002 to 2018 with day and month) and longitude, lattitude with the following code :
T = readtable('SouthernAfrica_0810.csv');
T.acq_date = datetime(T.acq_date,'F','dd/MM/uuuu');
SouthernAfrica_0810 = [T(:,6), T(:,1:2)];
save SouthernAfrica_0810.mat SouthernAfrica_0810
I would like to create tables representing the same thing for each month of each years wich make around 3000 tables (I need it to plot maps of fire pixels) but I'm not really feeling like doing it one by one...
Does anyone have an idea how to automatize the creation of those monthly tables for one the main table (I have linked one of the table in this message) ?
Thanks you, have a good day,
Thomas V.
8 comentarios
I assume you could set up a loop to do what you want, but it is not clear from your description what the workflow is that you are trying to automate. Please explain your problem in a little more detail. I don't think you want to end up with thousands of tables, so I assume that you want to somehow consolidate the data into a single overall table but that isn't quite clear in your description.What files are you reading from, what are the columns of data in these files, how are they named? What columns of data do you want in your final table(s)?
Thomas Vescovini
el 12 de Jul. de 2019
Peter Perkins
el 12 de Jul. de 2019
I'm afradi I don't really understand your description of the tables you have. It sounds like you have tables with three variables, and the table in your mat file seems to confirm that, but you describe them as having three rows. It's possible that you are mixing up the terms "row" and "variable".
Also if you have timestamps, it's likely that you want to use timetables.
Why is it that you want thousands of separate tables? There are functions (e.g. rowfun) that will let you do operations on groups of rows in a table, separately, without having to explicitly split up the table. It's also possible that you could pull out each group of rows one at a time, without having to create all of the thousands of tables all at once.
It would help if you gave a short clear example of what you have and what you want to do.
Guillaume
el 12 de Jul. de 2019
Actually, yes I need thousands of tables..
Then, your design is wrong. You shouldn't have one table per country or year or month. All this metadata should be stored together with the data in just one table. Right now, you're focusing your work on writing code to manipulate containers for your data whereas, if you had just one table, you'd be focusing your work on writing code to manipulate the actual data.
As Peter explained you can easily (as in: just one line of code required) write code to calculate monthly/yearly/whatever statistics if your data is in a single table.
dpb
el 12 de Jul. de 2019
+1 Jon+Peter+Guillaume (each)
Do NOT go the route of duplicating data in multiple files or tables or whatevers...simply retrieve data as needed for purpose from the global dataset--that way is trivial, the other is nothing but "there be dragons!" lurking...
Thomas Vescovini
el 14 de Jul. de 2019
Peter Perkins
el 15 de Jul. de 2019
If you are just making one plot, the simplest thing is to just create a smaller table. This code assumes a fiarly recent version of MATLAB, but you can do more or less the same thing using earlier versions:
>> tt = timetable(rand(100,1),rand(100,1), ...
'StartTime','1-Jan-2002','TimeStep',caldays(1), ...
'VariableNames',["X" "Y"]);
>> ttJan2002 = tt(timerange('Jan-2002','months'),:)
ttJan2002 =
31×2 timetable
Time X Y
___________ ________ _________
01-Jan-2002 0.81472 0.16218
02-Jan-2002 0.90579 0.79428
03-Jan-2002 0.12699 0.31122
04-Jan-2002 0.91338 0.52853
05-Jan-2002 0.63236 0.16565
>> plot(ttJan2002.X,ttJan2002.Y);
I realize that sounds counter to what people have been saying, but for one plot, it's fine.
If you want to make thousands of such plots, then I would think you'd want to put that code into a loop, or use rowfun to make the plots. To use rowfun, you will probably want to add a couple of grouping variables to your timetable for monh and year number, using the month and year functions on your datetime.
Thomas Vescovini
el 16 de Jul. de 2019
Respuestas (0)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!