1:46 pm


Silver
March 13, 2019

Dear MATLAB lovers,
I beg it's easy but I can't get it to work: I only want to display the date on the x-axis.
I'm using data stored by an IOT device. When downloading the data from MATLAB the CSV contains the date, so it must be somewhere ...
Here's my code fragment:
..
Month = thingSpeakRead(readChannelID,'Fields',FieldID,'dateRange',...
[datetime('now')-days(7),datetime('now')],'ReadKey',readAPIKey);
...
minAnzWerte= [length(Month)];
allData=[Month(1:minAnzWerte)];
...
plot((1:minAnzWerte),allData);
Works fine, but -of course- displays numbers for the x-axis.
When I use something like
t1=datenum(datetime('now')-days(7))
t2=datenum(datetime('now'))
t=t1:t2
plot(t,allData);
I'm receiving an error the the Vector lengths don't match ('Error using plot - Vectors must be the same length.'). And MATLAB's right.
Can you please help how I have to assign 'allData' and the plot-command?
Cheers
obod0002
3:05 pm


Moderators
March 7, 2017

I would recommend using a timetable.
add the name, value pair 'outputFormat', 'timeTable' to the thingSpeakRead function.
You can see that here:
https://www.mathworks.com/help/thingspeak/Use-Area-Plot-to-Compare-Traffic-Data-Sets.html
then
should do the trick if you change the FIELD1LABEL to your field 1 label. (case sensitive)
11:55 am


Silver
March 13, 2019

Thanks a lot for your help, cstapels. Unfortunately I'm still doing something wrong ...
timeAndData = thingSpeakRead(readChannelID,'Fields',FieldID,'dateRange',...
[datetime('today')-days(7),datetime('today')],'ReadKey',readAPIKey,...
'Outputformat','Timetable');
plot(timeAndData.TimeStamps,timeAndData.Fields);
=>
Error using tst (line 13)
Unrecognized table variable name 'TimeStamps'.
In case I'm using 'Timetable' instead of 'TimeStamps', MATLAB proposes to use the timetable-function.
8:11 am


Moderators
March 7, 2017

2:28 am


Silver
March 13, 2019

Nop, the hint with the timetable was also very helpful. But as I'm seeing the limitations for stacked plots I somehow want to avoid them.
My problem seems to be a basic one: how can I access the data itself? Having something like
FieldID = 4;
voltageWeek1t = thingSpeakRead(readChannelID,'Fields',FieldID,'dateRange',...
[datetime('today')-days(7),datetime('today')],'ReadKey',readAPIKey,...
'Outputformat','Timetable');
results in errors acessing the data itself:
plot(voltageWeek1t.Timestamps,voltageWeek1t.Fields);
=>
Error using tst 4er plot timestamp (line 44)
Unrecognized table variable name 'Fields'.
Same for plot(voltageWeek1t.Timestamps,voltageWeek1t.4);;
Somewhere else I had to use the given name for the field, i.e. '4: Spannung DG' (without the BLANK inbetween) but that doesn't like me either.
9:16 am


Moderators
March 7, 2017

6:05 am


Silver
March 13, 2019

yes, looking fine, thanks a lot for your help.
As always: if you get something to work you want more.
At the moment I'm experimenting with multiple plots and how to display the date on the x-axis (e.g. four plots, one week each). Let's see how far I can get. My goal is a plot where I can easily get the information on how much battery capacity has been used over the last few weeks and how much is still left.
Please don't spend to much time on the Umlauts ...
Most Users Ever Online: 166
Currently Online:
24 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:
estebanmateo93, mikewrite, onlinebusiness, winzy99, Zark_zeugan, StefanWiModerators: cstapels: 460
Administrators: Hans: 405, lee: 457