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
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
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
Steven Lord
2021년 12월 30일
Can you define variables with numbered names like X1, X2, X3, ... ? Yes.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!