Is there a command or function to "autocorrect" words in a sentence? Such as correcting the sentence "Teh cow jumped over the mono." to "The" and "moon".

1 回表示 (過去 30 日間)
Such as correcting the sentence "Teh cow jumped over the mono." to "The" and "moon".

採用された回答

Chad Greene
Chad Greene 2017 年 2 月 25 日
You could create a list of commonly misspelled words and corresponding correct spellings. For example,
str = 'Teh cow jumped over the mono.';
common_misspellings = {'Teh','The';
'mono','moon';
'trowzers','pants'};
regexprep(str,common_misspellings(:,1),common_misspellings(:,2))
ans =
The cow jumped over the moon.
  3 件のコメント
Stephen23
Stephen23 2017 年 2 月 26 日
編集済み: Stephen23 2017 年 2 月 26 日
@Chad Greene: mono is not a spelling mistake, it is a correctly spelled word in its own right. A solution that can parse sentences and distinguish between different word functions might be able to distinguish this, but as it stands it would be totally incorrect to use a simple list or even a dictionary to replace mono with moon. This concept would "correct" my sentence to read "My moon amplifier is broken", when in fact it was correct to begin with.
Adi Natan
Adi Natan 2017 年 3 月 27 日
The best and easy solution will be to add a spell checker only on commented lines.

サインインしてコメントする。

その他の回答 (2 件)

Star Strider
Star Strider 2017 年 2 月 24 日
Not in the MATLAB Editor.
This was actually discussed a while back in some thread. Since it’s possible that someone would want to name a variable ‘Teh’, or ‘summ’ to avoid overshadowing the sum function, the consensus was to just leave well enough alone.
  2 件のコメント
John D'Errico
John D'Errico 2017 年 2 月 24 日
Many people would be unhappy if the editor started to do this, because it would suddenly start creating bugs in their code.
Chad Greene
Chad Greene 2017 年 2 月 25 日
I don't think the question is about misspelled variable names.

サインインしてコメントする。


Jan
Jan 2017 年 2 月 26 日
  1 件のコメント
Adi Natan
Adi Natan 2017 年 3 月 27 日
編集済み: Adi Natan 2017 年 3 月 27 日
and in Unix? Why not just spell check the commented lines only? everything after % sign etc...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by