Can you optimize this row matching code?
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I have a huge matrix on which I need to do some matching operation. Here's the code I have written and it works fine, but I think there is some room to make it more optimized or write another code that does the matching in less time. Could you please help me with that?
rowsMatched = find(bigMatrix(:, 1) == matchingRow(1, 1) & bigMatrix(:, 2) == matchingRow(1, 2) & bigMatrix(:, 3) == matchingRow(1, 3))
The problem with this code is that I cannot use the && operand. So, in case one of the columns do not match the program still checks the next condition. How do you think I can avoid this?
Thank you
2 个评论
Matt Kindig
2014-4-23
Is matchingRow only a 1x3 vector? Or do you loop through all rows in matchingRow?
Can you post your full code?
采纳的回答
更多回答(1 个)
Matt Kindig
2014-4-23
How about this approach? Is it fast enough?
%bigMatrix is MxN, matchingRow is 1xN
rowsMatched = find(ismember( bigMatrix(:,1:3), matchingRow, 'rows'));
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!