Making tables from multiple doubles and datetimes

4 visualizaciones (últimos 30 días)
Noush
Noush el 30 de Dic. de 2021
Editada: Stephen23 el 30 de Dic. de 2021
Hello,
I would like to make 52 seperate tables from 52 columns that I have in three different arrays. How can I do that without typying it all out manually?
For your reference, this is my code:
W = readtable("WESTEN.csv"); %reads the table for western parts (azimuth = 90°)
O = readtable("OSTEN.csv"); %reads the table for eastern parts (azimuth = -90°)
S = readtable("SUEDEN.csv"); %reads the table for southern parts(azimuth = 0°)
Time = W{1:8736,"time"}; %extracts the time values for one year without NAN values
Power1 = W{1:8736,"P"}; %extracts power values, western components
Power2 = O{1:8736,"P"}; %extracts power values, eastern components
Power3 = S{1:8736,"P"}; %extracts power values, southern components
P = (Power1 + Power2 + Power3)/1000; %sums up the power values
T = split(Time,":"); %splits the time values into a time&date array
PV_Leistung = reshape(P,[168,52]); %Power Values split into weeks, each week is one column of PV_Leistung
Zeit1 = reshape((datetime(T(:,2),'InputFormat','HHmm','Format','h:mm a')),[168,52]); %extracts the time values from T and reshapes the form to match PV_Leistungen
[h,m] = hms(Zeit1); %gets the hours and minutes from it
Datum1 = reshape((datetime(T(:,1),'InputFormat','yyyyMMdd')),[168,52]); %extracts the date values from T and reshapes the form to match PV_Leistungen
So what I would like to do is to make 52 tables and in the first one, there is supposed to be the first columns of PV_Leistungen, Zeit1 and Datum1. In the second table, I want the second columns of those three and so forth. Is there a way to make a loop that does that automatically?
Thank you for your help :)
  1 comentario
Stephen23
Stephen23 el 30 de Dic. de 2021
Editada: Stephen23 el 30 de Dic. de 2021
"So what I would like to do is to make 52 tables and in the first one, there is supposed to be the first columns of PV_Leistungen, Zeit1 and Datum1"
Creating separate table is unlikely to make the data processing easier. Most likely you should be using one table with one variable/column to classify the groups and then use the standard group-processing data flows, e.g.:

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Dic. de 2021
YourTables = arrayfun(@(COLIDX) table(PV_Leistungen(:,COLIDX), ZEIT1(:,COLIDX), Datnum1(:,COLIDX), 'VariableNames', {'PV_Leistungen', 'Zeit', 'Datnum'}), 1:size(PV_Leistung,2), 'uniform', 0);
  4 comentarios
Noush
Noush el 30 de Dic. de 2021
okay, I have to work wih the tables quite a lot, is there a way to assign each of them to a letter instead of all of them being in YourTables?
Steven Lord
Steven Lord el 30 de Dic. de 2021
Can you define variables with numbered names like X1, X2, X3, ... ? Yes.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by