How to I parse an array of time stamp strings read into a table form a CSV file?
Afficher commentaires plus anciens
I have time stamped data collected into a csv file which I bring into Matlab as table.:
curr=
1053×2 table
Time Current
_________________________ ____________________________
"02/27/2024, 12:03:25 PM" -0.329
"02/27/2024, 12:03:30 PM" -0.14
"02/27/2024, 12:03:35 PM" -0.0765
"02/27/2024, 12:03:40 PM" -0.182
"02/27/2024, 12:03:45 PM" -0.292
I ultimately want to change the times into durations to plot the data vs. relative time; for example, the first entry would be time 0, the second would be 5 seconds later, etc...
I've tried something like this.:
time = split(curr.Time(:,1),'P')
time = split(time(:,1),',')
time = strip(time(:,2))
time = char(time(1:end-1))
time = duration(string(time(:,1:end-1)))
at this point I'm left with an array of duraitons. If I then subtract the first entry, I get the durations:
secs = time
secs = secs- secs(1)
However, because I got rid of the PM, I end up with negative seconds when the hour changed from 12 to 1. So, I tried and "if statement" to add 12 to any hour less than 12, but I couldn't do it.
if hour(string(time_curr_NHP))<12
hour(string(time_curr_NHP)) = hour(string(time_curr_NHP))+12
end
I'm pretty sure I've complicated this a lot more than it needs to be! There has to be a much simpler way to do this. I'd appreciate any help.
Thank you.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!