Concatenate Aphabets and numbers

2 visualizzazioni (ultimi 30 giorni)
joseph Frank
joseph Frank il 26 Ago 2013
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'

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 26 Ago 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)

Più risposte (1)

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

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by