Extract array information from date and create cell
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Luke McLellan
el 13 de Feb. de 2019
Comentada: Guillaume
el 20 de Feb. de 2019
Hi there,
I am having a little difficulty and was wondering if anyone had done something similar. I have a very large array (imported from Excel); 4884x2. This is data for each day over a 6 month period. I have also imported the dates, used datenumber and added them to the matrix. For each day there are elements every 15 minutes (new row). Unfortunately there are times missing resulting in reshape not being correct.
I am trying to create a cell array where each cell is an individual dates data (i.e all the time readings for the 4th of August).
My code currently reads in the excel file, dates and times.
I then
dates = datetime(datestr(dates));
days = day(dates); unidays = unique(days);
months = month(dates); unimonths = unique(months);
Followed by
datenumber = datenum(dates);
dt = unique(datenumber);
a = horzcat(datenumber,data);
for ii = 1:length(dt)
for iii = 1:32
% for iiii = length(data)
v{ii} = data(iii,:);
% end
end
end
An example of the excel sheet (only an extract) is:
2017/03/27 09:15 23.32362362 25.36263524
2017/03/27 09:30 14.26554124 52.36512337
2017/03/27 09:45 45.97456444 75.25463254
2017/03/27 10:00 41.69875632 37.95423965
With times going on to later in the day.
Thanks
Respuesta aceptada
Luke McLellan
el 19 de Feb. de 2019
3 comentarios
Guillaume
el 20 de Feb. de 2019
because I never used it, otherwise I would have.
That's the thing I don't understand. You come here asking for help, then completely ignore that help and use a complicated way of doing your thing. Again, it's rarely a good idea to split your data into multiple arrays/cell arrays/data. Matlab has plenty of function that can perform aggregration according to some grouping. You've never fully explained what you were doing, but for example loading an excel file and calculating the monthly average is just 2 lines:
data = table2timetable(readtable('somefile.xlsx')); %read the file into a timetable
monthlyavg = retime(data, 'monthly', 'mean'); %average by month
Más respuestas (1)
Guillaume
el 13 de Feb. de 2019
dates = datetime(datestr(dates));
%...
datenumber = datenum(dates);
The trip through datestr is unnecessary. And converting a datetime array to datenum is backward. datetime supports unique, and is much more practical than datenum.
Without an actual spreadsheet, we can only answer generically. Matlab has included tools for some time that help with dealing with time-based data. It looks like you're still using ancient tools ( datenum, xlsread, etc).
You should import your data with readtable, and convert it to a timetable (with table2timetable). Timetables have plenty of tools to deal with time, including retime which could be used to calculate daily/weekly/monthly/whatever statistics. It is very likely that splitting your original data into multiple table/arrays/whatever is not the right way to proceed.
0 comentarios
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!