Pair comparison in from other rows

조회 수: 2 (최근 30일)
raj singh
raj singh 2016년 5월 26일
답변: raj singh 2016년 5월 29일
I have:
A1=[3 4]
A2=[3 1 4]
A3=[3 2 1 4]
want to convert as:
(3,4)
(3,1)(1,4)
(3,2)(2,1)(1,4)
Now I want to check, is any pair common in all rows (except first rows)
For example: combination (1,4) is common in 2 and 3 row. In the result, I want this pair. Please help me to complete this program.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 5월 26일
A = {A1,A2,A3};
C = cellfun(@(x) hankel(x(1:end-1),x(end-1:end)),A,'un',0);
[a,~,c] = unique(cat(1,C{:}),'rows');
out = a(histc(c,1:size(a,1)) > 1,:);
  댓글 수: 5
raj singh
raj singh 2016년 5월 28일
Thanks Andrei sir, but i am using 2012a MATLAB, in which repelem and accumarray is not working. I don't have Matlab2016a. There is any other option to run run your given program.
raj singh
raj singh 2016년 5월 28일
Hello Image, Actually [A] represent the paths from one node to other node and i want common line in that paths. Do you have any suggestion for this ppg.

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

추가 답변 (1개)

raj singh
raj singh 2016년 5월 29일
A1=[1 4];
A2=[1 3 4];
A3=[1 2 3 4];
A4=[1 2 6 3 4];
I want common pairs from all row (vectors) except first row. It means my answer will be (3 4) and (1 2). First answer of Andrei sir, works perfect. May this is possible to print like this:
(Total no of row).........(Pair)............(How many times)
4 (3 4) 3
4 (1 2) 2

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by