这两个MATLAB字符串连接方法中哪一个更快?

时间:2011-04-28 12:01:54

标签: string matlab

以下哪种连接两个字符串的方法最快?

test = ['ssd' 'sdsd'];

test = sprintf('%s%s', string1, string2);

1 个答案:

答案 0 :(得分:4)

一个非常简单的测试显示

test = ['ssd''sdsd'];

更快。

具体做法是:

tic; for t=1:10000; test = ['ssd' 'sdsd']; end; toc;                
Elapsed time is 0.105972 seconds.

,而

tic; for t=1:10000; test = sprintf('%s%s', 'ssd', 'sdsd'); end; toc;
Elapsed time is 0.211863 seconds.