fprintf('Running %s.m ...\n', mfilename);
price = GetStockPrice(tickerSymbol);
price = GetStockPrice(tickerSymbol);
price = GetStockPrice(tickerSymbol);
fprintf('Done running %s.m\n', mfilename);
function price = GetStockPrice(tickerSymbol)
tickerSymbol = upper(tickerSymbol);
url = sprintf('https://www.google.com/finance/quote/%s:NYSE', tickerSymbol);
webPageContents = webread(url);
indexes = strfind(webPageContents, 'data-last-price=');
url = sprintf('https://www.google.com/finance/quote/%s:NASDAQ', tickerSymbol);
webPageContents = webread(url);
indexes = strfind(webPageContents, 'data-last-price=');
url = sprintf('https://www.google.com/finance/quote/%s:MUTF', tickerSymbol);
webPageContents = webread(url);
indexes = strfind(webPageContents, 'data-last-price=');
errorMessage = sprintf('Symbol %s not found in Google Finance in either NYSE or NASDAQ echange', tickerSymbol);
uiwait(errordlg(errorMessage));
indexes2 = strfind(webPageContents, 'Closed:');
if ~isempty(indexes2) && stockOrMutualFund == 1
for k = 1 : length(indexes2)
dateString = webPageContents(i1:i2);
dateString = datestr(now);
for k = 1 : length(indexes)
str = webPageContents(i1:i2);
quoteLocations = strfind(str, '"');
str = str(quoteLocations(1)+1 : quoteLocations(2) - 1);
y = year(datetime(datestr(now)));
fprintf('%s Stock Price = $%.2f on %s, %g.\n', tickerSymbol, price, dateString, y);