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????

 채택된 답변

KSSV
KSSV 2019년 8월 5일

0 개 추천

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

댓글 수: 3

galaxy
galaxy 2019년 8월 5일
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 2019년 8월 5일
It is better to sort indices....
galaxy
galaxy 2019년 8월 8일
yes.
I used "sortrows" and it is OK

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

제품

태그

질문:

2019년 8월 5일

댓글:

2019년 8월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by