How to ignore? | MATLAB | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





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

Register Lost password?
sp_Feed sp_TopicIcon
How to ignore?
Avatar
jacktheripper125

Silver
Forum Posts: 15
sp_UserOfflineSmall Offline
1
February 7, 2018 - 8:20 am
sp_Permalink sp_Print

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]

Avatar
Adarsh_Murthy

Forum Posts: 62
sp_UserOfflineSmall Offline
2
February 13, 2018 - 1:48 pm
sp_Permalink sp_Print

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:
36 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

ibgedubo

aogomaeqaza

ureomug

itixuwidouzuv

eilimir

memozupi

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee