1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab palindrome

  1. Oct 15, 2015 #1

    Moi

    User Avatar

    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
     
  2. jcsd
  3. Oct 15, 2015 #2

    Hesch

    User Avatar
    Gold Member

    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'.
     
  4. Oct 15, 2015 #3

    Moi

    User Avatar

    I used 'strcmp' instead? But I still get Error :-)
     
  5. Oct 15, 2015 #4

    Hesch

    User Avatar
    Gold Member

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Matlab palindrome
  1. Counting Palindromes (Replies: 3)

  2. Palindrome Java Program (Replies: 12)

Loading...