Concatenate Aphabets and numbers

1 view (last 30 days)
Hi,
I am trying the following code:
Alphabet=char('a'+(1:26)-1)';
[I,J]=ndgrid(1:26,1:26);
I=I'; J=J';
XX=[Alphabet(I(:)), Alphabet(J(:))];
XX=strvcat(Alphabet,XX);
Rw='2';
Rw=repmat(Rw,length(XX),1);
XX2=strcat([XX,Rw]);
I am ending up with a space between the alphabets and 2. How can I get rid of that? i.e. I want 'a2' instead of 'a 2'

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 26 Aug 2013
Alphabet=('a':'z')'
n=numel(Alphabet)
[I,J]=ndgrid(1:n,1:n)
I=I'; J=J';
XX=cellstr([Alphabet(I(:)), Alphabet(J(:))])
XX=[cellstr(Alphabet);XX]
Rw='2';
XX2=cellfun(@(x) [x Rw],XX,'un',0)

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 26 Aug 2013
az = cellstr(('a':'z')');
n = numel(az);
[ii,jj] = ndgrid(1:n);
a1 = [az;strcat(az(jj(:)),az(ii(:)))];
out = strcat(a1,'2');

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!