Write a function ispalin s that returns 1 if the string s is
Solution
There it goes the answer, it is a MATLAB function where, first af all the blanks are removed and then, all the letters are converted to lowercase. Then, the verification is done by using the function fliplr(\'string\'), that returns the string written backwards. With the if statements it is defined wether the string is a palindrome or not.
I have tested it and it works perfectly!
CODE OF THE FUNCTION
function [ y ] = ispalin( s )
s(s == \' \') = \'\'; %delete all spaces between the words
s = lower(s); % lowercase
%fliplr Flip matrix (or a string) in left/right direction.
if s== fliplr(s) %if the string is equal to the flipped string,
%it is a palindrome
y=1;
else
y=0;
end
end
EXAMPLES:
>> ispalin(\'Noon\')
ans =
1
>> ispalin(\'SolutionnoituloS\')
ans =
1
>> ispalin(\'Solution noituloS\')
ans =
1
>> ispalin(\'Solution noituloS forever\')
ans =
0
