IsPalindrome: Matlab Function to Check Word

  • Thread starter Thread starter Moi
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 3K views
Moi
Messages
3
Reaction score
0
I am trying to write a function called ispalindrome, with Matlab, It is supposed to check if a word is a palindrom or not.
It will then return a value True (1)or False(0) for each word.

I have tried to run this, but something seems to be wrong...
function isPalindrome (word)
word = input('isPalindrome ', 's');

if word == strcmpi(word);
disp ('1')
else
disp ('0')
end
 
Physics news on Phys.org
A google will tell you, that:

TF = strcmpi(string,string) compares two strings for equality, ignoring any differences in letter case. The strings are considered to be equal if the size and content of each are the same. The function returns a scalar logical 1 for equality, or scalar logical 0 for inequality.

Thus strcmpi('yes' , 'Yes') = true.

But 'yes' is not a palindrom. A palindrom is a word that is spelled the same way forward/backward, like 'refer' or 'bob'.
 
I used 'strcmp' instead? But I still get Error :-)