isPalindrome - %do not take spaces into account str =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function logical = isPalindrome(str) %function to check and see the string is a palindrome, if the string is, %then true will be displayed, if not, then false will be displayed; a %palindrom is a word or phrase that is written the same forwards and %backwards; palindromes are not case sensitive %usage: logical = isPalindrome(str) x = find(str==' '); str(x) = []; %finds and removes all of the spaces in the string, because palindromes.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: .. %do not take spaces into account str = lower(str); str = str(str>='a' & str<='z'); forward = str; %sets the forward expression equal to the string minus the spaces backward = str(end:-1:1); %sets the backward expression equal to the string reversed minus the %spaces logical = strcmpi(forward,backward); %determines whether the forward string is equal to the backwards string end...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Tech.

Ask a homework question - tutors are online