"permat" and more efficient coding
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Walter Roberson
2012 年 7 月 3 日
for k = 1 : length(listl)
lol{k} = cellstr( num2str( ixsL(:), [listl{k} '%u'] );
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で GPU Computing in MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!