音节词语索引超出矩阵维度。 MATLAB

时间:2017-10-07 09:20:00

标签: matlab indexing exceed

我得到了这段代码,但是有一个小问题 - 我在索引超出矩阵维度时遇到错误。当文本文件很大时,会出现此错误。请有人帮帮我吗?

Index exceeds matrix dimensions.
Error in getPolySyllWords>getSyllable (line 38)
InnerCode = InnerCode{1};
Error in getPolySyllWords>@(x)getSyllable(x)
Error in getPolySyllWords (line 8)
TextSyl = cellfun(@(x) getSyllable(x), TextCell);

我遇到了错误

function Syl = getSyllable(Word)
   if nargin == 0
       Word = input('What word do you want? ', 's');
   end
  if isempty(Word)
    Syl = 0;
    return
  end
Word = strrep(Word, ' ', '');

try
   Txt = webread(sprintf('http://www.dictionary.com/browse/%s?s=t', Word));
catch
    warning('Could not determine syllable for "%s". Returning 0.', Word);
    Syl = 0;
return
end

if isempty(InnerCode)
InnerCode = InnerCode{1};
CodeSrch2 = '>(?<Phonetics>[^\<]+)';
Phonetics = regexp(InnerCode, CodeSrch2, 'tokens');
Phonetics = [Phonetics{1}{:}];
else
% handle this case
Syl=1;
   return;
end

1 个答案:

答案 0 :(得分:0)

问题是,你的电话

SiteTxt = webread(sprintf('http://www.dictionary.com/browse/%s?s=t', Word));

为Word&#34; Dr&#34;返回标签

的一些SiteText
<span class="pron spellpron">[someResult] </span>

您正在扫描SiteText以保持为空。这在以下一行

InnerCode = regexp(SiteTxt, CodeSrch1, 'tokens');

产生一个空数组,导致&#34;指数超过矩阵维度&#34;错误。

当你输入两个不同的单词时,你可以自己测试一下&#34; doctor&#34;和&#34;博士&#34;直接在主页上:

enter image description here

请通过以下代码段扩展您的代码以处理这些情况:

if ~isempty(InnerCode)
    InnerCode = InnerCode{1};
    CodeSrch2 = '>(?<Phonetics>[^\<]+)';
    Phonetics = regexp(InnerCode, CodeSrch2, 'tokens');
    Phonetics = [Phonetics{1}{:}];
else
    % handle this case
    Syl=0;
    return;
end