Transform a matrix datetime in a one collumn datetime
Show older comments
Hello, I have a water level data in a matrix format, which each line represent the month and each collumn (from 1 to 47) the day of that month. I'd like to transform that matrix in one single collumn, in order to plot a time series of that data. However I have two kinds of gaps: the first one is because the months has different lengths (28,29,30,31); and the other class of gaps is a real gap, because there was problem with the sensor. So, I'm trying to concatenate all the lines data in one collumn, but without considering the first class of gap. Otherwise, the time of that data would be wrong. Does anybody could help?
obs: I'm using just the data with MediaDiaria ==1 1 (DailyMean) and NivelConsistencia == 1 (Consistency Level)
Kindest regards,
Felipe
This is the code that I've done up to now:
filename = ['C:\Users\felip\OneDrive\Desktop\Estacoes_ANA\Todas estacoes cotas 2\']
arquivo = [filename,num2str(2),'.csv'];
tabela = readtable(arquivo);
data = tabela.Data;
data_ini_all = find(data == '01/01/2022');
data_ini_a = data_ini_all(1);
data_fim_all = find(data == '01/01/2002');
if length(data_fim_all) > 1
data_fim_a = data_fim_all(end-1,1);
end
if length(data_fim_all) == 1
data_fim_a = data_fim_all(1,1);
end
tabela_sel = tabela(data_ini_a:data_fim_a,:);
ind_media = tabela_sel.MediaDiaria;
ind_consist = tabela_sel.NivelConsistencia;
index = find(ind_media == 1 & ind_consist == 1 );
nivel = tabela_sel(index,17:47);
teste = tabela_sel(index,:);
nivel_num = table2array(nivel)';
nivel_collumn = nivel_num(:);
nivel_certo = flip(nivel_collumn);
tempo = linspace(2002,2022,length(nivel_collumn))';
plot(tempo,nivel_certo,'k')
xlim([tempo(1) tempo(end)])
ylim([0 700])
grid on
1 Comment
The 'InputFormat' would appear to be 'dd/MM/yyyy' however parsing this file is going to be a definite challenge —
arquivo = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1326615/2.csv';
C = readcell(arquivo)
C{1:20,1}
... etc.
.
Answers (1)
Felipe Santana
on 16 Mar 2023
0 votes
Categories
Find more on 3-D Volumetric Image Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!