以下哪种连接两个字符串的方法最快?
test = ['ssd' 'sdsd'];
test = sprintf('%s%s', string1, string2);
答案 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.