- find the nearest element in Struct for each element in Week
- remove the elements that are two far apart in terms of time laps ; NB the minimal time delta found here is 52 seconds , so up to you to decide the time tolerance
Read images based on datetime
3 views (last 30 days)
Show older comments
Siegmund on 27 Jan 2023
Commented: Siegmund on 2 Feb 2023
I have +1000 images (in 'Struct') and would only like to use 'imread' on the images that equal the datetime in 'week1'.
How can I use a for loop (or other option) that only read the images during these certain times?
Thanks a lot for your suggestions
Mathieu NOE on 27 Jan 2023
this is a starter ....
In the middle of my brainstorming I was momentary worried that in 'Struct' the filename and date field seemed not to be consistent
like the first value are :
Timex(1).name = 'T_1_202110010600.jpeg' (and we could interpret that as 01 oct 2021 , 06:00 AM)
but date field gives :
Timex(1).date = '01-Oct-2021 08:14:06'
so after a few seconds of doubt I continued my work assuming that date field is correct and I should not take into account what Timex.name could suggest
Back to the code :
seems that both mat files will give two datenum arrays that do not really match 100% so there is a certain time gap between the two (if plot both you will see it)
now what i wanted to do is :
here I opted to keep only what is below 60 seconds of difference
you simply have to add your own code after imread ;
% load data
dd = datenum(start); % datetime data from file 'Week1.mat'
tt = [Timex.datenum]; % datetime data from file 'Struct.mat'
for ci = 1:numel(dd)
[v(ci),struct_idx(ci)] = min(abs(dd(ci) - tt));
delta_seconds(ci) = v(ci) * 24 * 60 * 60; % time delta between nearest datetime in 'Struct.mat' for a given datetime in 'Week1.mat'
% keep only files index for time delta below a certain threshold (in seconds)
week_ix = find(delta_seconds<=60);
struct_idx = struct_idx(week_ix);
% create list of files to read in 'Struct'
for ck = 1:numel(struct_idx)
ind = struct_idx(ck);
folder = Timex(ind).folder;
filename = Timex(ind).name;
Fdate = Timex(ind).date;
F = fullfile(folder,filename);
% your own code here
A = imread(F);
More Answers (0)
Find more on Data Type Conversion 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!