I have a bunch of files with timestamps associated with x and y coordinates. Currently the format of the timestamps is the following:
2016-11-08T15:55:01.7802880+00:00
I need to convert these into manipulatable format, as for example in milliseconds using matlab. I do not wan´t to extract only the milliseconds in the timestamps (example: .780), I need the absolute duration in milliseconds.
Thanks in advance!
Cheers
I'm sure there's a way to convert it with Matlab functions, but I've used this for the past little while.
Gets the job done.
ISO8601toserial.m File Exchange
Related
I have a Simulink block that calls a user-defined function. This function calls another function: thingspeakread.m (provided by the ThingSpeak Official Toolbox).
From here, I want two outcomes. Data (numeric type, vector), and timestamps (strings, vector).
[data,timestamps] = thingSpeakRead(___)
Now, I'm able to get the values of "Data" into a Scope without much of an issue (using coder.extrinsic('thingSpeakRead') and preallocating the variable to store such points). The issue I have is this: I need to make more sense of the data visualization, and for that purpose, I need to plot this "Data" against the information displayed in the timestamps vector. The timestamps varies per minute only.
What I'll try to do, but doesn't satisfies me a lot:
Convert the timestamp into a numeric value using datenum() using the format for 'mm/dd/yyyy HH:MM:SS'
This option sends back a huge number (which can be used to plot Data vs. Time indeed, but it doesn't look 'good' because the number is just too big and I don't like it).
I have thought about these too:
Convert date to Julian Date type.
Convert Hours, Minutes and Seconds into 3 different arrays.
But I don't see that getting me where I want (which is to plot Data vs. Time, being able to spot easily that the numbers displayed for "Time" are corresponding to an specific HH:MM:SS of a day).
Is there anything you can guys suggest, please? Thanks a lot in advance!
Edit 1: Can I use something like datetick() in Simulink?
What you are doing with converting to datenum is the only way to pass the "dates" down a Simulink signal.
There's no mechanism to display the time series, with dates displayed on the x-axis, without writing custom code.
If you don't need to display the time series as the simulation is running then just dump it to a mat file in your existing code, and generate the plot during post-processing.
If you want it to display as the simulation is running then you'll need to write a custom display block. This should be done as a Level-2 M-Code S-Function, but could be done using a MATLAB Function block. Either way you would input the datenum into the block and then convert the datenum back to a date - using something like datetime before generating the visualization, or afterwards using datetick.
I have a xlsx file containing time stamps in the format [mm:ss]
for example
00:01
00:04
00:07
00:10
00:12
I would like to import it in Matlab, but when I use
xlsread('namefile.xlsx') it converts the content of the column.
ps I run Matlab on Linux
What you get is a representation of the time as a single value. Luckily, for times there is no difference between excel and matlab, both use fractions of a full day. (while for dates there is a different "zero")
To get back minutes:seconds use:
datestr(a,'MM:SS')
Please note that MM is minutes while mm is month, this is a common cause for errors.
I am relatively inexperienced with matlab, as I only use it occasionally. I am trying to plot a large range of values against time and I am running into some problems.
The data, which is from a text file, with about 55000 entries, gives the information in the following format:
year month day hour minute second value
The seconds column has accuracy of 6 decimal places and there are about 24hrs worth of data.
What I want to do is plot the values against time, which works fine. However as a result of my code below, the x-axis has label ticks in serial date number format, which is not very useful when looking at the figure. I want to change the labels to something more useful such intervals of hours. However I am not sure how to go about doing this.
Here is the code:
A = dlmread('data.txt',' ');
time = datenum(A(:,1),A(:,2),A(:,3),A(:,4),A(:,5),A(:,6));
scatter(time,A(:,7),1)
axis([min(time) max(time) min(A(:,7)) max(A(:,7))])
I found a solution here: matlab ticks with certain labels however, the process here is manual and with so much information I don't want to do this manually. How would I automate this process? or is there a better way to do what I am trying to achieve?
EDIT: I also found this method: http://www.mathworks.com/help/matlab/ref/datetick.html#btpnuk4-1, however, I dont want to show the actual date, I rather want to show intervals of time, ie an hour or 30 minutes.
EDIT 2: I have found a somewhat satisfactory solution. It could still be improved upon, so I don't know if I should submit this as an answer to my own question or not, but here it is:
A = dlmread('data.txt',' ');
time = datenum(A(:,1),A(:,2),A(:,3),A(:,4),A(:,5),A(:,6));
temp= time(1);
timediff = time - temp;
scatter(timediff,A(:,7),1)
axis([min(timediff) max(timediff) min(A(:,7)) max(A(:,7))])
datetick('x', 'HH')
This takes the original time vector in serialized time format and subtracts the first time from all the subsequent times to get the difference. The it uses the datetick function to to convert that to hours. It isn't ideal because instead of 24 hours it goes back to 00, but its the best I have tried thus far.
With reference to the other article, you will have to follow the same method but in order to automate the process you'll need to form the vectors of xtick and xticklabels as you read in the data and after you've plotted the data change the xticks and xticklabels.
Its not difficult what you're trying to do, but I will need more details of how you want to organize the ticks to be able to exactly say the steps that you'd have to follow
Matlab serial time is simply days since January 1, 0000, so your timediff variable is really elapsed days (and fractions thereof) since the start of your experiment. If you want your x ticks to be elapsed hours you could multiply timediff by 24.
scatter(timediff * 24, values)
This avoids the weirdness that can arise when using datetick as well.
I have a MySQL table with over 6 million records, each with a epoch timestamp. I need to plot all the timestamps across time of day. In other words, I need to see how many timestamps are between 7am and 8am, 8am to 9am, etc - for all 24 hour blocks in day. I do not need them plotted by day of the week or month, just time in the day. Each timestamp is in UTC.
can someone help me?
You could use MySQL's FROM_UNIXTIME function to get date strings from the database, and dump the results into a file, which you can subsequently read into MATLAB. Next, one of the ways to extract the time of day of each record is to use MATLAB's datevec function, to get each component of the date string seperately:
datevec('2007-11-30 10:30:19')
ans =
2007 11 30 10 30 19
For instance, if you read in the data as one long vector with date strings, you could apply datevec to this vector, and subsequently grab the 'hour column' of the resulting matrix. Then, you can make a histogram of the counts using the hist or histc functions, depending on whether you want to specify bin centers or bin edges. If you have an hour column H, something like hist(H, 0:23) should work. The histc function might be a bit more natural for the nature of your data, but is slightly more involved; check the documentation.
I need to extract the dates from a set of data s.
I use the command s(x).comm.date where x can be changed for each person however it is returning the serial date number as 7.3244e+005 which just gives me the day but I need it to show much more detail something like this 732162.65994213.
I don't know if the data I have is already saving it as the shorthand format but it's a set of data from MIT and the help documentation shows it as the long hand format so I sincerely doubt this.
Yours,
MATLAB Newbie
Try typing the following help format or format long (for starters).
By default, Matlab displays 5 significant digits (calculations are done in appropriate floating-point precision, no matter how those variables are displayed). Refer to the documentation for different ways of displaying.