What is the most efficient method to compare two matrices for an identical row?

14 ビュー (過去 30 日間)
Kieran Clarke
Kieran Clarke 2018 年 3 月 18 日
コメント済み: Image Analyst 2018 年 3 月 18 日
I am currently comparing two matrices in order to find if there is an identical row between the two.
I am using ismember(A,B,'rows') and I am having issues as it is taking a large amount of time to compare the two due to their sizes. Is there another more efficient method that I can use?

回答 (2 件)

Image Analyst
Image Analyst 2018 年 3 月 18 日
You could use isequal() testing one row at a time to see if it was in the other matrix, though I don't know this would be faster than ismember(). How big are your matrices and how long is it taking?
  2 件のコメント
Kieran Clarke
Kieran Clarke 2018 年 3 月 18 日
Ah I didn't state clearly enough, the first one is tiny. Just one row. The second one is quite bit larger, up to 10000 ish rows of 2 columns. It slows down the app quite a bit.
However it may be more noticeable as I am modelling particles and comparing the positions to stop overlapping so it's delaying my redraw speed.
Image Analyst
Image Analyst 2018 年 3 月 18 日
You didn't answer my question above.
Are the values integers, or floating point/fractional values? If they're floating point, I think you'll have to use ismembertol().

サインインしてコメントする。


Greg
Greg 2018 年 3 月 18 日
Have you tried the following?
all(A==B,2);
I think you meant you are looking for a single row (variable A of size 1x2) in any of the rows of the larger matrix (variable B of size Nx2) - as opposed to matching rows in variables of the same size. The above will require the implicit expansion feature of R2016b (or manual expansion, as many will say is faster than the implicit expansion anyway).

カテゴリ

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