MATLAB Answers

How do I create a bar chart?

5 views (last 30 days)
I'm quite new to the field of manipulating my data and can't find any examples of my goal.
I have a channel with a field (fieldMotion) where I receive data from a motionsensor where I simply write ThingSpeak.setField(3, 1) for every motion detected. I would like to create a bar chart (in a Visualization) where I sum every 1's within an hour to show amount of motions per hour for a day. Also I would like to do the same per day for a week. Could anybody please help me with a working code I could use to make this work?

Accepted Answer

Christopher Stapels
Christopher Stapels on 13 Oct 2020
Use ThingSpeakRead to get your data, i reccomend a timetable:
data = thingSpeakRead(channelID,'Fields',[1,4],'NumPoints',3,'OutputFormat','TimeTable');
% might have to add api key for private channels
Use retime to create the sum
sumData=retime(data,'hourly','sum'); % I think daily is also possible for your second request.
plot your bar chart
You will probably have to change TemperatureF to the name of your field. Leave the semicolon off the first command to see the varaible names when you run it.
Then add it to the channel where you want to see it.
Christopher Stapels
Christopher Stapels on 22 Dec 2020

Sign in to comment.

More Answers (0)



More Answers in the  ThingSpeak Community

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!