How to check data by years?
Afficher commentaires plus anciens
Dear all,
I have a time series that starts from 1996 and end on 2017, the data I have are hourly data (so everyday I have 24 points). Each hour of my data has a quality flag to let me know if the data is useful or not. These quality flags are in the form of letters. So far I have a cell arrays of the years and the flags (24 flags per day because they are hourly flags).
I want check the number of the flag 'D' that I have for every year. So I want to basically have a table that tells me for every year from 1996 to 2017, the number of 'D' flags do I have.
Thank you, M
2 commentaires
Jan
le 28 Août 2017
Start with explaining the problem with useful details. What class and size do the data have? Is it a table or struct, matrix or cell? What is "the flag D"? Post a relevant part of the inputs and explain, what you want as output. Then it is easier to post an answer.
Réponse acceptée
Plus de réponses (1)
Steven Lord
le 30 Août 2017
Build a sample table.
rng default
n = 60;
theyear = randi([2010 2020], n, 1);
themonth = randi(12, n, 1);
theday = randi(28, n, 1);
flags = randi(5, n, 1);
T = table(theyear, themonth, theday, flags, ...
'VariableNames', {'Year', 'Month', 'Day', 'Flag'});
% Select the Flag variable for all rows in the table
% whose Year variable is equal to 2017
flagsFor2017 = T{T.Year == 2017, 'Flag'};
% How many are there?
size(flagsFor2017, 1)
% Look at the raw data
flagsFor2017
% Bin them. I use 1:6 here because the flags can range from 1 to 5
% If I had used 1:5 then 4 and 5 would have been in the same bin
histcounts(flagsFor2017, 1:6)
Alternately if you want to process all the years and all the flags at once, use histcounts2 or histogram2.
histogram2(T.Year, T.Flag)
From visual inspection of this particular data set the flag 2 in 2017 was the most common combination.
1 commentaire
Mariam Salem
le 31 Août 2017
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!