Trying to compare datetimes in array to a separate predetermined datetime via function/for loop/if statement
Show older comments
Hi all,
I am trying to write a function that removes all rows of data after associated with a certain datetime. The idea was for a loop to go through each row of my datetime column and compare that datetime to 2024-07-06. If greater (after this date) the row gets deleted via my if statement. This is the code I wrote:
function [output] = remove_after_07(file_name)
new = file_name ;
for index = 1:length(file_name.date_only)
if index > 2024-07-06
index = []
end
end
output = new ;
endThis is the error I get:
‘Comparison is not defined between datetime and double arrays.’
How can I make it compare the actual dates listed in the column instead of the array?
Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Calendar 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!