File: ef230-2023-08/www/examples/temperature_from_web.m Download
%% pull current temperature from a web site
% This is a crude example of extracting data from a web service
% It is very page dependent.
% Spring, 2011

clear all; clc;
% get text (XML) from web site
txt = urlread('')

% set starting and ending strings
startstring = 'temp_f data="';
endstring = '"/>';

% look for first start string
n = length(istart);
if n==0, error('did not find start string'); end

% look for first end string after this
iend = strfind(txt(istart:end),endstring) + istart - 2;
if n==0, error('did not find end string'); end
iend = iend(1);

% extract the value
valtxt = txt(istart:iend);
valnum = str2num(valtxt)