Index Exceeds matrix dimensions Error? Not your typical cause.

1 view (last 30 days)
I have a feeling it has to do with the source code because the URL reading is working. But the expression I am looking for is broken down by new lines, which is where the problem seems to be coming from. I've tried adding "/n" to the line breaks but it does not work. Any idea what's going on here?
The error is on the last line of code. temp = ....
URL = 'http://finance.yahoo.com/q/bs?s=AAC+Balance+Sheet&annual';
options = weboptions('Timeout',Inf);
str = webread(URL,options);
[assetsmatch, assetsnomatch] = regexp(str,'<strong>Total Assets</strong></td><td align="right"><strong>([0-9.]*) </strong>','tokens','match');
temp = str2double(assetsmatch{1,1});

Answers (1)

Walter Roberson
Walter Roberson on 2 Sep 2015
No, it is the usual reason: you assumed that data was present without checking it first.
According to my browser, there is a lot of white space that you are missing in your regular expression. Newlines. Spaces.
I do not have a version of MATLAB new enough to have webread(). If I use urlread() then the <strong> is not there, and instead there are <span with style: entries nearby, with the implication being that the entire presentation is being controlled by CSS (Cascading Style Sheets) and those are causing the <strong> .
Also, your subexpression for the numbers is using [0-9.] but the numbers being presented (at least when I look) have no '.' and instead contain ',' such as 145,952 . Perhaps it shows up as '.' when you view it. The magic of CSS.
I suggest simply matching against 'Total Assets[^0-9]+([0-9.,]+)'

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!