[英]Syllables Words Index exceeds matrix dimensions. Matlab
我使此代碼正常工作,但是有一個小問題-索引超出矩陣尺寸時出現錯誤。 當文本文件很大時,將出現此錯誤。 有人可以幫我嗎?
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
問題是你的電話
SiteTxt = webread(sprintf('http://www.dictionary.com/browse/%s?s=t', Word));
為單詞“ Dr”返回一些SiteText,其中標記
<span class="pron spellpron">[someResult] </span>
您正在掃描SiteText的內容為空。 在下面的行中
InnerCode = regexp(SiteTxt, CodeSrch1, 'tokens');
產生一個空數組,該數組導致“索引超出矩陣維數”錯誤。
您可以在首頁上直接輸入兩個不同的單詞“ doctor”和“ dr”來自己進行測試:
請使用以下代碼段擴展您的代碼,以處理這些情況:
if ~isempty(InnerCode)
InnerCode = InnerCode{1};
CodeSrch2 = '>(?<Phonetics>[^\<]+)';
Phonetics = regexp(InnerCode, CodeSrch2, 'tokens');
Phonetics = [Phonetics{1}{:}];
else
% handle this case
Syl=0;
return;
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.