How can I make a logical array by comparing two date vectors?
Show older comments
Hello, could you please help me on the following issue. I imported an Excel file containing the vector of dates (44 by 1, type - cell):
[temp, holidays]=xlsread('Holidays.xlsx', 'Tabelle1', 'A1:A44').
Then, I created the date vector with a step of 1 minute:
start_date = datenum('18-Apr-2015 16:30:00');
end_date = datenum('19-Apr-2015 10:00:00');
interval = 10/24/60;
date = datestr(start_date:interval:end_date);
My goal is to create a logical array that puts 1 if the date from the second (longer) vector equals the date in the first vector and 0 otherwise.
I tried the code below, but I have problems with data formats, which I cannot solve. Error using datenum (line 179) DATENUM failed.
Caused by: Error using dtstr2dtnummx Failed on converting date string to date number.
criteria=[];
for i=1:length(date)
if day(holidays(i))==day(date(i)) && month(holidays(i))==month(date(i)) && year(holidays(i))==year(date(i))
criteria(i)=1
else
criteria(i)=0
end
end
Can please anyone help on that? Thanks a lot in advance!
2 Comments
Azzi Abdelmalek
on 29 Apr 2016
You can make your question clear by posting a sample of your imported data.
Ekaterina Serikova
on 29 Apr 2016
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 29 Apr 2016
0 votes
You can use the ismember function
3 Comments
Ekaterina Serikova
on 29 Apr 2016
Azzi Abdelmalek
on 29 Apr 2016
Ok, post a sample of your data
Azzi Abdelmalek
on 29 Apr 2016
[~,a]=xlsread('holidays.xlsx');
b={'03-Apr-2015 16:30:00','06-Apr-2015 16:30:00','07-Apr-2015 16:30:00','08-Apr-2015 16:30:00'},;
bb=datestr(b,'dd.mm.yyyy'),
out=ismember(a,bb)
Categories
Find more on Dates and Time 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!