2013-03-03 47 views

回答

6

您可以使用CELLFUN匿名函数:

b = cellfun(@(x)[10 x],a,'UniformOutput',0) 

要回答@tmpearce评论我用一个简单的脚本来测量运行时间:

a = {[1 2 3]; [4 5]; [6 7 8 9]}; 
tic 
a = cellfun(@(x)[10 x],a,'UniformOutput',0) 
toc 
a = {[1 2 3]; [4 5]; [6 7 8 9]}; 
tic 
for ii=1:numel(a) 
    a{ii} = [10 a{ii}]; 
end 
toc 

结果:

Elapsed time is 0.002622 seconds. 
Elapsed time is 0.000034 seconds. 
+3

这确实避免尽管可能值得检查一下简单循环是否有速度优势 - cellfun/arrayfun往往非常慢 – tmpearce 2013-03-03 01:08:03

+0

对这样一个小数据的比较几乎没有意义 – Amro 2013-04-22 10:01:40

相关问题