MATLAB: “permat” and more efficient coding

repeated elements

Dear all,
I have this list of countries
listl={'ATl' 'BEl' 'ESTl' 'FRl' 'DEl' 'GRl' 'IEl' 'ITl' 'NETHl' 'PTl' 'SLOVAKl' 'SLOVENl' 'ESPl'};
and the following command
ixsL=repmat( [1: 2], [3,1] );
lol= arrayfun( @(ii) sprintf( 'ATl%u',ii), ixsL (:), 'uni', false );
As you can see the ATl inside the expression changes every time we refer to a new country.
For instance, if we refer to 'BEl' we have
lol= arrayfun( @(ii) sprintf( 'BEl%u',ii), ixsL (:), 'uni', false );
My goal is to create an "if statement" such that
*if listl(1) *to obtain the output of
lol= arrayfun( @(ii) sprintf( 'ATll%u',ii), ixsL (:), 'uni', false );
if listl(2) to obtain the output of
lol= arrayfun( @(ii) sprintf( 'BEl%u',ii), ixsL (:), 'uni', false );
I was thinking something like
lol= arrayfun( @(ii) sprintf( 'k%u',ii), ixsL (:), 'uni', false );
where k=listl(1) or k=listl(2).
this approach will save me my time instead of typing BEl or ATl inside the arrayfun

Best Answer

for k = 1 : length(listl)
lol{k} = cellstr( num2str( ixsL(:), [listl{k} '%u'] );
end