Vectorizing multiple string comparison
古いコメントを表示
Is there a way to significantly speed up this loop, perhaps by vectorizing it? Inputs in attachment. I do not have a Matlab version with "string" functions.
d = a';
for i = 1:numel(a)
d{i} = c(strcmp(a{i}, b), :);
end
I tried working my way from the inner part with cellfun, but either I am not getting it right or it is not the good approach:
aux = cellfun(@strcmp, a, b); % does not work
2 件のコメント
Walter Roberson
2017 年 1 月 27 日
That file is an Octave file that would take a bunch of work to read in MATLAB.
This is the wrong resource to be asking about performance improvement for Octave.
Paolo Binetti
2017 年 1 月 27 日
採用された回答
その他の回答 (1 件)
Walter Roberson
2017 年 1 月 27 日
1 投票
ismember can be used between cell arrays of strings. The two-output version can be used to find the indices, which you can then use to index into c.
3 件のコメント
Paolo Binetti
2017 年 1 月 27 日
Walter Roberson
2017 年 1 月 27 日
Flip the order around, ismember(b, a) .
Paolo Binetti
2017 年 1 月 28 日
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!