Why is "findstr" not recommended compared to strfind.

5 ビュー (過去 30 日間)
Andrew Reibold
Andrew Reibold 2013 年 6 月 27 日
Is it simply because you can flip the inputs in strfind however you want, (making it more flexible), or is it actually more resource intensive. I have findstr alot in my code and it works, but should I go back and edit it?
I don't know why it bothers to give me the warning "findstr is not recommended. try strfind instead"

採用された回答

per isakson
per isakson 2013 年 6 月 27 日
編集済み: per isakson 2013 年 6 月 27 日
R2012a says: "Note: findstr will be removed in a future release. Use strfind instead." This is a reason to replace findstr in code, which will be around for some years in the future.
And strfind is somewhat faster
n2 = 1e6;
a = 'a':'p';
buf = a( randi( [1,16], [1,n2] ) );
str = reshape( buf, 1, [] );
pattern = a( randi( [1,16], [1,4] ) );
tic, ix1 = strfind( str, pattern ); toc
tic, ix2 = findstr( str, pattern ); toc
all( ix1==ix2 )
returns
Elapsed time is 0.001971 seconds.
Elapsed time is 0.003049 seconds.
ans =
1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by