Return to 9. MATLAB Scripts

Barometric Trend

This MATLAB visualization displays the latest three hours of barometric pressure and determines the trend based on the pressure difference over the three hours. The values are taken from your ThingSpeak channel at the time your webpage is opened. You must manually update the chart by refreshing your browser.

% Displays 3 hours of barometric pressure
% and determines trend
% (C) 2020, Karl Berger
% IoT Kits
% w4krl.com/iot0kits
% 16 July 2017
% 22 November 2018 - add comments

%%% ENTER YOUR CHANNEL ID
 chID = 286120;                            % enter your channel ID

 baroSLPField = 4;                         % IoT Kits field assignment
 dataMins = 185;
 [baro3hr, time] = thingSpeakRead(chID, 'Fields', baroSLPField, 'NumMinutes', dataMins);
 len = length(baro3hr);                    % number of data items
 deltaP = baro3hr(len) - baro3hr(1);       % pressure change over 3 hours
 strDeltaP = num2str(deltaP, 2) + " mbar"; % convert to string with two decimal points
 % add a plus sign in front of positive values
 % negative values automatically have a minus sign
 if deltaP > 0
     strDeltaP = "+" + strDeltaP;
 end
 % find term for deltaP
 if deltaP > 6.0
     strTrend = "Rising Very Rapidly";
 elseif deltaP > 3.6
     strTrend = "Rising Quickly";
 elseif deltaP > 1.6
     strTrend = "Rising";
 elseif deltaP > 0.1
     strTrend = "Rising Slowly";
 elseif deltaP > -0.1
     strTrend = "Steady";
 elseif deltaP > -1.6
     strTrend = "Falling Slowly";
 elseif deltaP > -3.6
     strTrend = "Falling";
 elseif deltaP > -6.0
     strTrend = "Falling Quickly";
 else
     strTrend = "Falling Very Rapidly";
 end  
 % plot the three-hour span
 plot(time, baro3hr, '-o')
 title('Trend: ' + strTrend + ' (' + strDeltaP + ' over 3 hours)')
 xlabel('3-hour span')
 ylabel('millibars (hPa)')
 grid on

Permanent link to this article: https://w4krl.com/iot-kits/matlab-scripts/barometric-trend/