### MATLAB >> palindrome code

I'm trying to do a standard palindrome (Madam I'm Adam). I know that I have to just toss out the spaces and punctuation, and then test whether it's true or false.
Problem is how do I toss out spaces and punctuation?

a='hello world'
s=double(a)

now how do I toss out spaces and punctuation?

Thanks!

### MATLAB >> palindrome code

No reason to convert to double. As for removing spaces and punctuation
help isspace
a(isspace(a))=[];

Here's a random way for getting rid of punctuation that just occurred to me. Since lower case letters don't equal upper case letters but lower punctuation does = upper punctuation
a = a(lower(a)~=upper(a))

a='hello world'
isequal(a,fliplr(a))

a='level'
isequal(a,fliplr(a))

### MATLAB >> palindrome code

Don't toss out things, keep what is required.

a = a(ismember(a,intersect(a,['a':'z' 'A':'Z'])));

### MATLAB >> palindrome code

That won't work if you want to keep numbers :(

This would account for numbers:
a = a(lower(a)~=upper(a)|ismember(int8(a),48:57))

### MATLAB >> palindrome code

% I'm not sure isspace will remove ALL punctuation marks.

doc isletter

% might be more useful here.

% Or (another way):

palTestString = 'le; ve l.';
a = palTestString(isletter(palTestString));
strcmp(a,fliplr(a))

### MATLAB >> palindrome code

I wonder... how does isletter() work with non-English letters?

Aren't there some alphabets in which the lower-case equivalent of some of the
upper-case characters require 2 characters to write? I thought I once
encountered something like that in German.

### MATLAB >> palindrome code

% Perhaps one more tweak is needed:

palTestString = 'Le; ve l.';
a = lower(palTestString(isletter(palTestString)));
strcmp(a,fliplr(a))

### MATLAB >> palindrome code

I think Walter's is the best solution since it can be easily adapted to include numbers or specific symbols etc.
So we want all letters, numbers and the pound sign:

a = a(ismember(lower(a),intersect(a,['a':'z' '0':'9' '#'])));

### MATLAB >> palindrome code

ssssh!

---
"Oh Walter! You are the master of obfuscation!!"

### MATLAB >> palindrome code

German has the lower-case , which turns into a two S's in upper case:
http://en.wikipedia.org/wiki/

### MATLAB >> palindrome code

Ah, I was thinking of that letter but I wasn't sure about it.

The implication would seem to be that in at least some cases, two S's in a row
should become a single lower-case character if everything is converted to
lowercase for comparison.

In German, is it possible for two upper-case S's to appear adjacent to each
other (possibly with punctuation or spaces between) that do not represent this
letter? I seem to recall that German capitalizes proper nouns, but are there
cases where a capital letter can occur in the middle of a word or at the end
of a word? In English, capital letters can occur in the middle of a word only
for names derived from other languages (e.g., VanHooke), or for acronyms
(e.g., ATM); or for trademarks (e.g. MicroSoft); or for abbreviations (e.g.,
kHz). Alternately, is it possible in German for two lower-case s's to appear
adjacent to each other in a word and _not_ to be ??

The point of the above questions is of course to look for palindromes that
would break if SS is lowercased as , and to look for palindromes which are
only successful if SS is lowercased as ss, and to look to see whether SS to
is a mechanical translation or has to be guided by some more intelligence.

Several of the algorithms proposed used tolower() _after_ removing the spaces
and punctuations, but if it is possible in german to have a group of letters
(word or acronym) that can end in S followed by space/punctuation followed by
a word that starts with a single S, then in order for the lower-casing to be
accurate it would have to be done _before_ the punctuation was removed, as
otherwise after removal you might end up with an SS pair that was *not* in
lower-casing. Mind you, it would also be interesting to find one in German
that worked exactly the other way, dependant on the two SS's being jammed
together and matched with ...

### MATLAB >> palindrome code

Dear Walter,

I cannot see the benefit of the INTERSECT here. Simpler:
a = a(ismember(a, ['a':'z', 'A':'Z']));
(or with '0':'9' etc).

Jan

### MATLAB >> palindrome code

```Hi,

I am trying to find palindromes and near palindromes within
text strings using regular expressions. I used a regexp from
the Matlab help to get

test = 'aaaaCDEFGGFEDCbbbbbJKLMNOaabbONMLKJaaaa';
P = regexp(test,'(.{3,13}).?(??@fliplr(\$1))','match');

which correctly gives P = 'CDEFGGFEDC'.

I would also like to be able to find the near palindrome
starting with JKL. By near palindrome I mean something like
JKLMNOaabbONMLKJ where the aabb part may be two or more
nonpalindromic characters. Unfortunately, I think my regular
expression Kung Fu is too weak to see how to do that. Anyone
out there know a simple way to do this?

Thanks,
J

```

```Hi,Firends

A C++ code like this:

char evfile[16];

fp is a file name;
I want to transform it to MATLAB code, what should I do?

Thanks for you help!
```

```hi,

i want to convert a C++/C code to Matlab code (M-file) and
viceversa, what instructions do i need??

Do you know some simple example that illustrate this?? or
topic?? something specific and short if possible

```Hi,