Get Data from a 16414x6 array to 365 arrays with size(48x3)

1 vue (au cours des 30 derniers jours)
Andreas Tsiartas
Andreas Tsiartas le 19 Fév 2021
Commenté : Andreas Tsiartas le 19 Fév 2021
Hello,
I Have an array that consist meteorological Data for 365 days.
For every day (24 Hours) i have 48 entries in that table because it is seperated for every 30 minutes.
That gives me a table with 16414 rows and 6 coloums.
What i need is to seperate the days in different tables with only 3 of the coloums of the original one.
For example i want to have 365 tables with size (48,3)

Réponse acceptée

Andreas Tsiartas
Andreas Tsiartas le 19 Fév 2021
I came up with a different solution. I am attaching it here if it helps anyone.
I basically created an index for eax individual array i was trying to create. I scanned over the whole table and then assigned the values to different arrays to work with the values
IndxFeb=1;
IndxMar=1;
LenghtDataset = height(Dataset_Table); %Get the number of rows in the Dataset_Table
%Checks the Timestap to assign values to the correct arrays
for i=1:size(Dataset_Table)
%----------------------------------------------------------------------
%Check if it's January
if (Dataset_Table{i,1} <= datetime(2019,01,31))
JanuaryTime(i)= Dataset_Table{i,1};
JanuaryGHI(i)= Dataset_Table{i,4};
JanuaryTamp(i)= Dataset_Table {i,6};
end
%----------------------------------------------------------------------
%End of January Test
%----------------------------------------------------------------------
%----------------------------------------------------------------------
%Check if it's February
if (Dataset_Table{i,1} >= datetime(2019,02,01) && Dataset_Table{i,1} <= datetime(2019,02,29))
FebruaryTime(IndxFeb)= Dataset_Table{i,1};
FebruaryGHI(IndxFeb)= Dataset_Table{i,4};
FebruaryTamp(IndxFeb)= Dataset_Table {i,6};
IndxFeb = IndxFeb + 1;
end
%----------------------------------------------------------------------
%End of February Test
%----------------------------------------------------------------------
%----------------------------------------------------------------------
%Check if it's March
if (Dataset_Table{i,1} >= datetime(2019,03,01) && Dataset_Table{i,1} <= datetime(2019,03,31))
MarchTime(IndxMar)= Dataset_Table{i,1};
MarchGHI(IndxMar)= Dataset_Table{i,4};
MarchTamp(IndxMar)= Dataset_Table {i,6};
IndxMar = IndxMar + 1;
end
%----------------------------------------------------------------------
%End of March Test
%----------------------------------------------------------------------
.......
  2 commentaires
Rik
Rik le 19 Fév 2021
You are making your life needlessly complicated. If you discover you want a minor change, you will now have to change your code in 12 places, instead of 1. It is of course up to you, but I would seriously suggest using something else. You can even use the month function to index that array:
x={'jan','feb','mar'};
x{month(datetime)}%datetime without input returns the current date and time
ans = 'feb'
Andreas Tsiartas
Andreas Tsiartas le 19 Fév 2021
I didn't know about that function. That's great news!
This is the first time i am using MATLAB for some Data Analysis.
I will try it and update the post!
Thank you Rik!

Connectez-vous pour commenter.

Plus de réponses (1)

Rik
Rik le 19 Fév 2021
I would suggest using a 3D array instead. If you dynamically generate variable names you are shooting yourself in the foot. You can use the reshape function to reshape your data to a 3D array.
  1 commentaire
Andreas Tsiartas
Andreas Tsiartas le 19 Fév 2021
Modifié(e) : Andreas Tsiartas le 19 Fév 2021
First of all Thanks for your time. I tried it but i found a different solution that did the job!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by