"permat" and more efficient coding
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 3 Jul 2012
for k = 1 : length(listl)
lol{k} = cellstr( num2str( ixsL(:), [listl{k} '%u'] );
end
More Answers (0)
See Also
Categories
Find more on GPU Computing in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!