given the date format 27-jun-2023 11:11:38, how to subset basd on hours only for each day in matlab

You can start by converting the date format into datetime format. After that, you can use the hour function to extract hours from the datetime and unique function to obtain unique dates. Then, you can loop over the unique dates, and use find function to subset the hours based on each date.

Here's an example code to subset based on hours only for each day:

main.m
% Date string
dateStr = '27-jun-2023 11:11:38';

% Convert to datetime format
dt = datetime(dateStr, 'InputFormat', 'dd-MMM-yyyy HH:mm:ss');

% Extract hours
hours = hour(dt);

% Get unique dates
dates = unique(dt.Date);

% Loop over unique dates
for idx = 1:numel(dates)
    % Find hours for current date
    dateHours = hours(dt.Date == dates(idx));
    
    % Do whatever you want with the hours here
    disp(dateHours)
end
428 chars
21 lines

This will output the hours for each unique date found in the datetime string.

related categories

gistlibby LogSnag