IsPalindrome: Matlab Function to Check Word

  • Thread starter Thread starter Moi
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
The discussion centers on creating a Matlab function called isPalindrome to check if a word is a palindrome, returning True (1) or False (0). The initial implementation uses the strcmpi function incorrectly, leading to errors in determining palindrome status. A palindrome is defined as a word that reads the same forwards and backwards, such as 'refer' or 'bob'. Suggestions include reviewing the syntax and functionality of the strcmp function, as well as ensuring proper input handling. The conversation emphasizes the importance of understanding string comparison in Matlab for accurate palindrome detection.
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 :-)
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
10K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
11
Views
4K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K