Making tables from multiple doubles and datetimes

8 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2021-12-30
编辑:Stephen23 2021-12-30
"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.:

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2021-12-30
YourTables = arrayfun(@(COLIDX) table(PV_Leistungen(:,COLIDX), ZEIT1(:,COLIDX), Datnum1(:,COLIDX), 'VariableNames', {'PV_Leistungen', 'Zeit', 'Datnum'}), 1:size(PV_Leistung,2), 'uniform', 0);
  4 个评论
Noush
Noush 2021-12-30
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 2021-12-30
Can you define variables with numbered names like X1, X2, X3, ... ? Yes.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by