Akby - 1 month ago 15

C Question

I'm currently working on a small project on handling time difference on MATLAB. I have two input files;

`Time_in and Time_out`

`2315 (GMT - Hours and Minute)`

I've read both

`Time_in' and 'Time_out`

Answer

this is one of several possible solutions:

First, you should convert your time strings to a MATLAB serial date number. If you've done this, you can do your calculation as you want:

```
% input time as string
time_in = '2115';
time_out = '2345';
% read the input time as datenum
dTime_in = datenum(time_in,'HHMM');
dTime_out = datenum(time_out,'HHMM');
% subtract to get the time difference
timeDiff = abs(dTime_out - dTime_in);
% Get the minutes of the time difference
timeout = timeDiff * 24 * 60;
```

Furthermore, to calculate the time differences correctly you also should put some information about the date in your time vector, in order to calculate the correct time around midnight.

If you need further information about the function `datenum`

you should read the following part of the MATLAB documentation:

https://de.mathworks.com/help/matlab/ref/datenum.html

Any questions?