0
votes

I want to do something like scatter(timesRefined, upProb) where timesRefined is a cell array in which each entry is a string corresponding to a time moment, such as 8:32:21.122 and upProb is simply a vector of numbers with same length as cell array. What is the most convenient way to do this?

2

2 Answers

1
votes

You can convert your timesRefined cell to a numeric representation of date with datenum

>> timesRefined = {'8:32:21.122','9:30:54.123'};
>> datenum(timesRefined)
ans =

          734869.355800023
          734869.396459757

The resulting number expresses a date as days from the epoch. Since you are not concerned with days, just time, and provided your observations are contained within one day, you can simply take the fractional part of the datenum output:

>> datestr(mod(datenum(timesRefined),1))
ans =

 8:32 AM
 9:30 AM

and do scater(mod(datenum(timesRefined),1),upProb)

EDIT:

As pointed out by Pursuit, you can use the result of datenum directly as your x values and use datetick('x','HH:MM:SS.FFF')

0
votes

strsplit from the Matlab file exchange should help. If all values are numeric, you'll get a matrix back.

timestr = '8:32:21.122';
timenum = strsplit(timestr,':');
convmat = [60*60; 60; 1];
time_in_seconds = sum(timenum .* convmat);