"permat" and more efficient coding

1 visualizzazione (ultimi 30 giorni)
Sabbas
Sabbas il 3 Lug 2012
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

Risposta accettata

Walter Roberson
Walter Roberson il 3 Lug 2012
for k = 1 : length(listl)
lol{k} = cellstr( num2str( ixsL(:), [listl{k} '%u'] );
end

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by