How to get unique timestamps | MATLAB IoT Analytics | Forum

The ThingSpeak community site has been upgraded to a new site. This site is currently in read-only mode. You can ask questions or post and read discussions on the new site.

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
How to get unique timestamps
No permission to create posts
October 3, 2016
1:57 am

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

I have the matlab code below but it sometimes fails because of duplicated time-stamps in the data. (this causes 'bar' to fail with 'XData must be unique' error).

Wondering how to get a unique set of timestamps then rejoin them to the values (I dont particularly care which of the duplicated values gets matched).  My newbie attempts to use the 'unique' function do not work because the row as a whole is considered unique even when the timestamps are the same.


02/10/2016 01:30 -436.43
02/10/2016 01:30 -390.61
02/10/2016 01:35 -390.68
02/10/2016 01:35 -390.6

% Draw a bar graph of Interconnector power
% red for positive, blue for negative

power = thingSpeakRead(150393,'OutputFormat','Table','NumDays',3);
pos=unique(power(power.Interconnect > 0,[1,4]));
neg=unique(power(power.Interconnect <= 0,[1,4]))
figure('position', [0, 0, 1200, 700])
hold on
hold off
datetick('x','ddd dd/mm')
title 'South Australian Interconnector Load'
ylabel 'Net Power (MW)'
legend('Buying Power','Selling Power','Location','northwest')
axis 'tight'

October 4, 2016
12:32 pm

Forum Posts: 62
Member Since:
August 25, 2015
sp_UserOfflineSmall Offline

Since you are looking to find rows with unique timestamps, call unique() only on Timestamps column. I added a couple lines of code to your snippet and it should work now.

power = thingSpeakRead(150393,'OutputFormat','Table','NumDays',3);
[~, uniqueIndx] = unique(power.Timestamps);
power = power(uniqueIndx, :);
pos= power(power.Interconnect > 0,[1,4]);
neg= power(power.Interconnect <= 0,[1,4]);
<insert the remaining lines of code>

Take a look at the link below for further info about unique() function:


I am curious about the cause for duplicate timestamps. How are you adding data to channel 150393 - from a device, or MATLAB Script tied to a TimeControl/React or another method?  

October 4, 2016
8:44 pm

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

Thanks Adarsh, that worked perfectly.

The repeated timestamp appears to be an artefact of the start of daylight savings time. The values are coming from a script that scrapes data off a website : the data includes a timestamp so I use 'created_at' to set this time in the thingspeak record.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
28 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:

kusmumichael, petersmith99, Rambant, blakeharriss09, optisol, Niyonzima Fils

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457