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
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 个评论
Rushan Arshad
2017-9-21
Cam Salzberger
2017-9-21
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 Community
类别
在 帮助中心 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!