Dear all,
I need to get same elements of matrix (follow row) same as intersect function such as following:
  1. a = [ 3 0; 3 0; 1 3];
  2. b = [ 3 0; 3 1; 1 3];
  3. [same,~,~] = intersect(a,b,'rows')
  4. > same =
  5. 1 3
  6. 3 0
I used Matlab Function block and put intersect but has error:
The first operand is not sorted in ascending order. Use SORTROWS first
Anyone knows????

 Akzeptierte Antwort

KSSV
KSSV am 5 Aug. 2019

0 Stimmen

[same,ia,ib] = intersect(a,b,'rows') ;
a(sort(ia),:)

3 Kommentare

galaxy
galaxy am 5 Aug. 2019
Thank you, but it also same before.
Following is model:
model.PNG
function same = calc(a, b)
[same,~,~] = intersect(a,b,'rows');
same(sort(same),:);
end
KSSV
KSSV am 5 Aug. 2019
It is better to sort indices....
galaxy
galaxy am 8 Aug. 2019
yes.
I used "sortrows" and it is OK

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Gefragt:

am 5 Aug. 2019

Kommentiert:

am 8 Aug. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by