フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

speed up for long list matching

3 ビュー (過去 30 日間)
Eric
Eric 2012 年 1 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Is there a better way to do this as the length of idtsall is more than 30k? Thanks in advance.
for n = 1:length(idtsall)
ind = find(ismember(idts, idtsall{n}));
if(ind > 0)
ranktsall(n) = rankts(ind);
else
ranktsall(n) = 0;
end
end

回答 (3 件)

Walter Roberson
Walter Roberson 2012 年 1 月 5 日
The two-output ismember will return the index in the second output, allowing you to skip the find() step. The first output of insmember() will indicate whether it was found or not.
[foundit, ind] = ismember(idts, idtsall{n});
if foundit
ranksall(n) = rankts(ind);
else
ranksall(n) = 0;
end
Now, to check: idtsall is a cell array of vectors? All the same size or different sizes?
  3 件のコメント
Jan
Jan 2012 年 1 月 5 日
Which string is of the same size as what other string?
Eric
Eric 2012 年 1 月 5 日
The strings in the cell array of both idtsall and idts are of the same size.

Jan
Jan 2012 年 1 月 5 日
What type and dimension is idts?
ranktsall = zeros(1, length(idtsall); % Pre-allocate!
for n = 1:length(idtsall)
ind = find();
if all(ismember(idts, idtsall{n})) % Explicite ALL
ranktsall(n) = rankts(ind);
end
end
With a pre-allocation the processing is much faster and the else branch is not required anymore.
There can be much faster methods depending of the size and dimensions of idts and the contents of idtsall.
  1 件のコメント
Eric
Eric 2012 年 1 月 5 日
idts is a subset of idtsall.

Eric
Eric 2012 年 1 月 5 日
I'm thinking.. could we have something like this..
ranktsall = zeros(length(idtsall), 1);
[idx, val] = matching(idts, idtsall); % I have no idea about this part
ranktsall(idx) = val;
This would be perfect! idts is a subset of idtsall.
CAN SOMEONE HELP???

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by