use MATLAB A palindrome is a word, phrase, number, or other sequence of characte
ID: 3816499 • Letter: U
Question
use MATLAB
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as “madam” or “racecar”. Sentence-length palindromes may be written when allowances are made for adjustments to capital letters, punctuation, and word dividers, such as "A man, a plan, a canal, Panama!", "Was it a car or a cat I saw?" or "No 'x' in Nixon". – Wiki Definition.
Write a MATLAB script that accept user input and checks whether it is a palindrome. The evaluation is based on letters only in a string. All other characters are ignored. Case differences among letters are also ignored. Validate palindrome examples include:
“babab”
“aaaaa”
“AAaa”
"A man, a plan, a canal, Panama!"
“AA 123 aa”
“” (empty string)
“--------” (string without letters and numbers)
Obiectives Learn how to process strings with MATLAB Problems A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as "madam" or "racecar". Sentence-length palindromes may be written when allowances are made for adjustments to capital letters, punctuation, and word dividers, such as "A man, a plan, a canal, Panama. "Was it a car or a cat I saw?" or "No 'x' in Nixon Wiki Definition Write a MATLAB script that accept user input and checks whether it is a palindrome. The evaluation is based on letters only in a string. All other characters are ignored. Case differences among letters are also ignored. Validate palindrome examples include: "babab A Aaa A man, a plan, a canal, Panama AA 123 aa (empty string) (string without letters and numbers) Command Window Enter a piece of text: A man a plan, a canal, Panama It is a palinedrome. Enter a piece of text: abcdba Not a palindrome.Explanation / Answer
st = input('Enter a piece of text:','s');
st = lower(st);
l = size(st,2);
md = floor(l/2);
hat=0;
j = l-1;
for i = 1:l
if(i>j)
break;
end
if(isletter(st(i))==1)
continue;
end
if(isletter(st(j))==1)
j=j-1;
continue;
end
if(st(i)~=st(j))
hat=1;
break;
end
j=j-1;
end
if(hat==0)
disp('Palindrome.');
else
disp('Not a palindrome.');
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.