How to ignore? | MATLAB | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
How to ignore?
No permission to create posts
February 7, 2018
8:20 am
Avatar
jacktheripper125

Silver
Members
Forum Posts: 18
Member Since:
January 18, 2018
sp_UserOfflineSmall Offline

Hi. I would like to ignore data outside a range, ie if the data is over 400 or below 0.

this is what i am using now, occasionally the sensor goes mad. I have had a try but im just messing up my data more with errors, this is my current code.

 

[code]

 

% TODO - Specify URL of the page to read data from
url = 'https://api.thingspeak.com/apps/thinghttp/send_request?api_key=xxxxxxxxxxxxx';
% TODO - Specify the target string to search in webpage
targetString = 'is';

% TODO - Replace the [] with channel ID to write data to:
writeChannelID = xxxxxxx;
% TODO - Enter the Write API Key between the '' below:
writeAPIKey = 'xxxxxxxxxxxxx';

%% Scrape the webpage %%
data = urlfilter(url, targetString);
display(data);

%% Analyze Data %%
% Add code in this section to analyze data and store the result in the
% analyzedData variable.
analyzedData = data;

%% Write Data %%
thingSpeakWrite(writeChannelID, analyzedData,'Fields',[1], 'WriteKey', writeAPIKey);

 

[/code]

February 13, 2018
1:48 pm
Avatar
Adarsh_Murthy

MathWorks
Members
Forum Posts: 62
Member Since:
August 25, 2015
sp_UserOfflineSmall Offline

Hi,

How many points does the output of urlfilter command contain? For the code examples below, I am assuming that it only contains a single point.

There are several options available based on what is required for your applications. Here are a couple options that might be relevant:

Option 1: If the data is outside the desired range, then you can choose not to write that data to 'writeChannelID':

% TODO - Specify URL of the page to read data from
url = 'https://api.thingspeak.com/apps/thinghttp/send_request?api_key=xxxxxxxxxxxxx';
% TODO - Specify the target string to search in webpage
targetString = 'is';

% TODO - Replace the [] with channel ID to write data to:
writeChannelID = xxxxxxx;
% TODO - Enter the Write API Key between the '' below:
writeAPIKey = 'xxxxxxxxxxxxx';

%% Scrape the webpage %%
data = urlfilter(url, targetString);
display(data);

%% Analyze Data %%
% Add code in this section to analyze data and store the result in the
% analyzedData variable.

maxValue =400 ;

minValue = 0;

if (data > maxValue) || (data < minValue)

% Do nothing because data is outside the range defined [0, 400]

else

%% Write Data %%
thingSpeakWrite(writeChannelID, data,'Fields',[1], 'WriteKey', writeAPIKey);

end

 

Option 2: If the data is outside the desired range, then you can write a predefined value to 'writeChannelID'. For example, if the value is greater than 400, then you write 400 and if the value is less than 0, then you write 0:

 

% TODO - Specify URL of the page to read data from
url = 'https://api.thingspeak.com/apps/thinghttp/send_request?api_key=xxxxxxxxxxxxx';
% TODO - Specify the target string to search in webpage
targetString = 'is';

% TODO - Replace the [] with channel ID to write data to:
writeChannelID = xxxxxxx;
% TODO - Enter the Write API Key between the '' below:
writeAPIKey = 'xxxxxxxxxxxxx';

%% Scrape the webpage %%
data = urlfilter(url, targetString);
display(data);

%% Analyze Data %%
% Add code in this section to analyze data and store the result in the
% analyzedData variable.

maxValue =400 ;

minValue = 0;

if (data > maxValue)

    analyzedData = maxValue;

elseif (data < minValue)

    analyzedData = minValue;

else

   analyzedData = data;

end

%% Write Data %%
thingSpeakWrite(writeChannelID, analyzedData,'Fields',[1], 'WriteKey', writeAPIKey);

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

terranceqh2, DianeEmids, Alanawaype, uqovitay, ufijifode, manish01

Administrators: Hans: 387, lee: 457