"permat" and more efficient coding

1 回表示 (過去 30 日間)
Sabbas
Sabbas 2012 年 7 月 3 日
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

採用された回答

Walter Roberson
Walter Roberson 2012 年 7 月 3 日
for k = 1 : length(listl)
lol{k} = cellstr( num2str( ixsL(:), [listl{k} '%u'] );
end
  1 件のコメント
Sabbas
Sabbas 2012 年 7 月 3 日
thanks walter!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGPU Computing in MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by