Problem with plotting data using line plot and scatter plot?
Ältere Kommentare anzeigen
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)
Antworten (1)
Cam Salzberger
am 21 Sep. 2017
0 Stimmen
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 Kommentare
Rushan Arshad
am 21 Sep. 2017
Cam Salzberger
am 21 Sep. 2017
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
Communitys
Weitere Antworten in ThingSpeak Community
Kategorien
Mehr zu Line Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!