Speeding up comparison using strcmp
古いコメントを表示
Hello! I have a list of approximately 2 million records and I would like to compare the records with a list of devices which generates those records. My code is as follows where "c" is the list of records and "device" is the list for distinct devices:
for ii = 1:length(device)
idx = ( strcmp(c,device(ii,:)) );
lidx = find(idx);
devid{ii} = lidx;
end
The problem is the above code takes too long time (more than an hour). Would you please tell me know how to reduce execution time?
Many thanks!
2 件のコメント
David Sanchez
2015 年 1 月 13 日
What do you mean by "list".
Are c and device sell arrays?
採用された回答
その他の回答 (1 件)
David Sanchez
2015 年 1 月 13 日
If you have getnameidx available in your system, you might transform your device to a cell:
device_cell = celstr(device);
and then look for their position within c:
device_positions = getnameidx(c,device_cell);
which will return the position of your devices within the c cell
3 件のコメント
Titus Edelhofer
2015 年 1 月 13 日
Hi David,
this function is from Financial Toolbox. And although it generally speaking is doing what Yongmin wants, it does not handle the multiple occurrences (from the help: NOTE: It will not find multiple occurrences of a name ...). Titus
Titus Edelhofer
2015 年 1 月 13 日
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!