Is there any way to check spelling from within MATLAB?

32 views (last 30 days)
I would like to be able to check the spelling of a word within MATLAB without having to write my own spell checking algorithm.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Jun 2013
There is currently no spell checking functionality contained in MATLAB. However, using ActiveX, you can implement the spell checker of another program and bring the results back to MATLAB. The following example shows how to do this using Microsoft Word's spell checker:
function suggestion = checkSpelling(word)
%CHECKSPELLING uses MSWord to correct spelling
% CHECKSPELLING(WORD) checks the spelling of WORD and returns spelling
% suggestions as a cell array. If WORD is spelled correctly, CHECKSPELLING
% will return empty brackets. If no suggestions are found. CHECKSPELLING
% returns 'no suggestions'.
%Start the Word ActiveX Server and check the spelling of WORD
h = actxserver('word.application');
h.Document.Add;
correct = h.CheckSpelling(word);
if correct
suggestion = []; %return empty if spelled correctly
else
%If incorrect and there are suggestions, return them in a cell array
if h.GetSpellingSuggestions(word).count > 0
count = h.GetSpellingSuggestions(word).count;
for i = 1:count
suggestion{i} = h.GetSpellingSuggestions(word).Item(i).get('name');
end
else
%If incorrect but there are no suggestions, return this:
suggestion = 'no suggestions';
end
end
%Quit Word to release the server
h.Quit
Currently there is no workaround for platforms other than Windows.
  1 Comment
Andrea H
Andrea H on 6 Jul 2018
Do you know how to change the language (e.g., to German)?

Sign in to comment.

More Answers (1)

zxc
zxc on 3 Mar 2014
Edited: MathWorks Support Team on 19 May 2021
I get an error:
"??? Input argument "word" is undefined.
Error in ==> word at 10 correct = h.CheckSpelling(word);"
I have installed ActiveX, but not sure how to use and run with the code above. How do I get the output as https://stackoverflow.com/questions/22120074/can-matlab-check-the-spelling-error-of-certain-article-paragraph ?
  3 Comments
Chuck
Chuck on 20 Mar 2017
You would need to check word by word. You can write a loop for that.

Sign in to comment.

Products


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!