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)

답변 (1개)

Cam Salzberger
Cam Salzberger 2017년 9월 21일

0 개 추천

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

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

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2017년 9월 21일

댓글:

2017년 9월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by