How can I easily extract element from a big matrix?
Show older comments
I have a bigg matrix [365x24] whic represtens a specific property for each hour and day of the year.
It can be read like this:
The first line has of 24 elements whit elements whic are corresponding to the 00:00 to 23:00 of Monday; the second is Tusday and so on with the Seventh that is Sunday and then it restart with the following weekt.
The first 31 row represent the days of January the following 28 rows rapresents the days of february and so on...
I would like to extrat some specific intervals of data for each month and for the whole year, that are
F1--the elements fom 8:00- to 19:00 (8 am to 7 pm) for each moday to friday interval
F2--the elements and 20:00 to 23:00 for each Monday to Friday interval and Saturday all day from 0:00 to 23
F3-- The elements from 00:00 to 7:00 (midnight -7 am) for each Monday to Saturday interval; and al Sundays all day fro 00:00 to 23
The intervals are summarized in figure

I tried to do it mannualy but it's a messy and slow method, how can i do it quickly?
%For example for F1
A=randi(365,24);
F1m=[A(1:5,8:19);A(8:12,8:19);A(15:19,8:19); A(22:26,8:19);A(29:33,8:19); A(36:40,8:19);
A(43:47,8:19);A(50:54,8:19);A(57:61,8:19);A(CYear(64:68,8:19);A(71:75,8:19); A(78:82,8:19)... ];
%and the sum
F1=sum(sum(F1m));
9 Comments
KSSV
on 18 Jul 2022
How do you have the data? Is it in excel? Attach your data. This can be achioeved by converting your date, times into datetime class and then by searching what you want.
Pietro Fiondella
on 18 Jul 2022
KSSV
on 18 Jul 2022
Attach your data.
Pietro Fiondella
on 18 Jul 2022
dpb
on 18 Jul 2022
Don't make it so hard...use the paper clip icon and attach the .mat file.
It also probably would be simpler to turn the time variables into datetimes (assign an arbitrary year) and convert to a timetable so can use the features of retime (although I've not tried to manually recreate a similar data structure to test; that's why you should attach yours...folks are far more likely to poke at a problem if there's something there to play with rather than have to also make it up from scratch...)
Pietro Fiondella
on 18 Jul 2022
Adam Danz
on 18 Jul 2022
I assume you have a 1x24 vector that defines the time for each column or at least you the time of the first column and the duration of each column which could be used to compute the 1x24 time vector.
I also assumes you have a 365x1 vector of dates that define each row or a starting date and the duration of each row that could be used to compute the date vector.
Once you have those values, you could create a timetable as @dpb suggested above. Once you have a timetable, your task becomes much simpler.
Pietro Fiondella
on 18 Jul 2022
Accepted Answer
More Answers (0)
Categories
Find more on Timetables 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!