creating a repeated matrix
1 次查看(过去 30 天)
显示 更早的评论
HI all,
I have the following code
k1=repmat({'S1'}, [3,1]) ;
k2=repmat({'S2'}, [3,1]) ;
k3=repmat({'S3'}, [3,1]) ;
k4=repmat({'S4'}, [3,1]) ;
k5=repmat({'S5'}, [3,1]) ;
k6=repmat({'S6'}, [3,1]) ;
ktotal= [k1; k2;k3;k4;k5;k6];
Is it possible to create "ktotal" with a more clever way? Probably with a loop?
thank you in advance
0 个评论
采纳的回答
per isakson
2012-7-2
编辑:per isakson
2012-7-2
This is a more "clever" way:
ixs = repmat( [1:6], [3,1] );
ktotal = arrayfun( @(ii) sprintf('S%u',ii), ixs(:), 'uni', false );
However, a for-loop is probably the "best" way:
ktotal = cell( 6*3, 1 );
for ii = 1:6
ix = 3*(ii-1)+1;
ktotal( ix : ix+2 ) = {sprintf('S%u',ii)};
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!