- 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 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Mathieu NOE
2023-1-27
hello Sigmund
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
load('Week1.mat')
load('Struct.mat')
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'
end
% plot(delta_seconds)
min(delta_seconds)
% 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);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!