Problem with plotting data using line plot and scatter plot?

Hello everyone, I am getting data from 2 sensors for liquid measurement onto my thingSpeak channel. I want to create a MATLAB visualization that combines data from 2 fields of the channel, combine the data for a day and display it in the form of scatter or 2-d line plot. How can I do that? I am new to MATLAB and thingSpeak. I am currently using the following code but it is just displaying the chart not the lines or scatter dots in both cases. What could be the problem?
CID = ;
rkey= '';
datetimeStop = dateshift(datetime('now'),'start','hour');
datetimeStart = dateshift(datetime('now'),'start','hour') - hours(130);
t = datetime(2017,9,14);
%data = thingSpeakRead(CID,'DateRange',[datetimeStart,datetimeStop],...
%'Fields',1);
data = thingSpeakRead(CID,'NumPoints',9,...
'Fields',2);
averageData = mean(data);
averageData
x=datetimeStart;
totalLiquid = averageData * 10;
totalLiquid
y=totalLiquid;
thingSpeakScatter(x, y)

Answers (1)

Hello Rushan,
In this case, "x" is equal to "datetimeStart", which is a scalar value. "y" is equal to "averageData", which is possibly a scalar value as well (can't tell if the data was originally a vector or matrix). Only a single point is likely to show up in this case. Check the data you are plotting before you plot it, and see if it is the data you are expecting to plot.
-Cam

2 Comments

Hello Cam, Thank You for your answer and I agree average data is just one value. I want to display this averagedata for different intervals like previous hour then 8 hours and then 16 hours. How can I get that data and plot it?
It'd probably be easiest to simply loop through the different intervals and calculate the mean at each point. So if you wanted to produce a vector with a mean of every 10 values, you could do something like:
data = rand(100, 1);
windowSize = 10;
avg10 = zeros(numel(data)/windowSize, 1);
for k = 1:numel(avg10)
startIdx = 1+windowSize*(k-1);
avg10(k) = mean(data(startIdx:startIdx+windowSize));
end
If you didn't have regular intervals, and wanted to do it based on the datetime vector or something, you'd probably want to calculate the limits and use logical indexing. Might be harder to preallocate though, depending on how your data is.
-Cam

Sign in to comment.

Communities

More Answers in the  ThingSpeak Community

Categories

Asked:

on 21 Sep 2017

Commented:

on 21 Sep 2017

Community Treasure Hunt

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

Start Hunting!