Time difference between two dates on x-axis | MATLAB IoT Analytics | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Time difference between two dates on x-axis
No permission to create posts
May 21, 2018
3:06 am
Avatar
BoOM
New Member
Members
Forum Posts: 1
Member Since:
May 21, 2018
sp_UserOfflineSmall Offline

Hey everyone,

i really looking forward for some help.

I try to calculate the time difference between two RFID loggin Data´s. I mapped the UID´s from the cards with "1". So ich only get 1 on y-axis and the time on x-achsis.

See here: https://thingspeak.com/channels/497889

I really dont´t know what function to take for calculating Time 2 - Time 1 = min

etime?timeit? Tic? Toc? Plot time ? Datediff ? Diff ?

and how do i get what i need ? The introductions from this functions are not givin examples from that what i want :-/ Always the last value of the table minus the second last value...

Can i take this code for starting ? ( And underneath the function i need...)

//
readChannelID = 497889;
% TODO - Replace the [] with the Field ID to read data from:
fieldID1 = 1;

% Channel Read API Key
% If your channel is private, then enter the read API
% Key between the '' below:
readAPIKey = 'XXX';

%% Read Data %%

% Read first data variable
[data,timestamps] = thingSpeakRead(497889,'Fields',[1],'NumMinutes',360)
//

then i get something like this:

//data =

9
9
9
9

timestamps =

4×1 datetime array

21-May-2018 08:21:36
21-May-2018 08:21:53
21-May-2018 08:22:13
21-May-2018 08:30:36
//

Many thanks for some help in advance 🙂

May 21, 2018
8:14 am
Avatar
rw950431

Top
Members
Forum Posts: 279
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

I suspect that the diff() or caldiff() functions are what you are looking for. Hopefully one of the Matlab experts will chime in with the right syntax..

May 22, 2018
4:19 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

When you read the data, MATLAB takes care of interpreting the times and you can subtract the directly.

[myData,myTimes]=thingSpeakRead(497889,'NumPoints',2);

numMinutes=minutes(myTimes(2)-myTimes(1));

I sometimes prefer to use a timetable:

myTableData=thingSpeakRead(497889,'NumPoints',2,'OutputFormat','timetable');

numMins=minutes(myTableData.Timestamps(2)-myTableData.Timestamps(1));

Does that help you do what you wanted to do?

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

qkpham, SANGAMNATH B, swatiiot, kalyanigaware16@gmail.com, Romi, Drakan01

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457