Create table from an other table

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

Jon
Jon el 12 de Jul. de 2019
Editada: Jon el 12 de Jul. de 2019
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
Thomas Vescovini el 12 de Jul. de 2019
Actually, yes I need thousands of tables... The purpose of my work is to plot monthly maps of fire pixels in around 20 regions of the world! Right now I can't plot them from the entire table and that's why I need monthly tables so I can create those maps from these tables.
The originals files are .csv with 14 rows, I created tables with 3 of the 14 rows. The first row is the date named "acq_date", the second is the latitude named "latitude", and the third row is longitude named "longitude".
For the new tables I need the same rows but I want to split the main tables considering the first row (acq_date) which have the following form dd/MM/uuuu for select each month of each years. For exemple create a table with the date, the longitude and the latitude but only for January 2002 (xx/01/2002) and for each month until december 2018 (xx/12/2018).
Tell me if it is more clear ?
Peter Perkins
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
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
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
Thomas Vescovini el 14 de Jul. de 2019
Thanks for your help, I just started working with matlab so I'm a bit confuse sorry... So for exemple I have one table (see the attached file in the first message), and I want to select only the month of January 2002, knowing that the first variable is the date "acq_date" with the form dd/MM/uuuu, and plot the selection using the second and the third variable respectivly "latitude" and "longitude" on the map.
How can I do this ?
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
Thomas Vescovini el 16 de Jul. de 2019
Ok thank you, I think I will try it but you are right, I'm just going to lose my time with it...
I'm closing the subject!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Productos

Versión

R2016a

Etiquetas

Preguntada:

el 12 de Jul. de 2019

Comentada:

el 16 de Jul. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by