Use spreadsheet with datetimes as a source input in simulink.

7 views (last 30 days)
Hello
I could use some help trying to use data from a excel file / csv file as an input source for my simlulation.
The file contains the columns datetime, triage, priority, and an example of that looks like this:
2017-08-20 07:53:00,orange,4
2017-08-20 08:09:00,green,2
2017-08-20 08:17:00,yellow,3
2017-08-20 08:23:00,green,2
2017-08-20 08:24:00,yellow,3
2017-08-20 08:25:00,green,2
2017-08-20 08:41:00,green,2
2017-08-20 08:50:00,green,2
2017-08-20 09:17:00,yellow,3
2017-08-20 09:19:00,yellow,3
2017-08-20 09:22:00,yellow,3
2017-08-20 09:25:00,yellow,3
2017-08-20 09:33:00,green,2
2017-08-20 09:37:00,green,2
2017-08-20 09:40:00,green,2
In our simulation, we have an entity "patient" which is connected to a waiting queue (not FIFO, but based on priority)
I'm trying to provide data for the patient entity, and use the datetimes, so an event should be generated in that timeframe (minutes)
so the second event (2017-08-20 08:09:00,green,2) will be fired 18 minutes after the first event (2017-08-20 07:53:00,orange,4)
What i have tried is to use the import module from a spreadsheet, but we are getting an error that we need to convert our datetimes to numeric values. I'm just not sure how to do that correct.
simulation.png
Hope someone can help

Answers (1)

Mark McBroom
Mark McBroom on 24 Nov 2018
Try changing the format of the date column in your excel spreadsheet to "general". THis will represet the date as number of days since 1900. Assuming your are using date/time for relative calcuations, then you can then use this number directly in your Simulink model. If your algorithm needs absolute time, you'll have to add 1900 to the value.
Note that MATLAB has a function to convert Excel time to MATLAB date-time. https://www.mathworks.com/help/matlab/ref/datetime.exceltime.html

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!