Filter löschen
Filter löschen

How do i calculate the Number of records that exist in both tables?

2 Ansichten (letzte 30 Tage)
Dear all,
I have two tables A and B .. where both tables have 5000 records , both tables have the following contents:
table A:-
Country name Code
USA 1
UK 1
RSA 2
KSA 3
etc..
Table B:-
Country name Code
USA 1
WSN 1
IRN 3
KSA 4
etc..
i need to calculate the following percentages: {per values for example 50%}
Per1=Percent of records that exist in Table A with similar code number as in Table B.
per2=percent of records that exist in Table A with different code number than in Table B.
Per3=Percent of records that exist in Table B with similar code number as in Table A.
per4=percent of records that exist in Table B with different code number than in Table A.
for example: number of records in table A with code number =1 is 75;
number of records in table A with similar code number =1 and similar to table B is 60;
then per1 = 60/75 * 100%;
etc. for others....
thanks for any help
  6 Kommentare
Image Analyst
Image Analyst am 9 Jun. 2017
Sorry, not until you help us help you. Remember when I asked "Attach the two table data files."? I'll check back later, perhaps tomorrow.
ahmed obaid
ahmed obaid am 9 Jun. 2017
Ok, i have attached my tables... for rows that not included in both .. eliminated .. thanks

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 9 Jun. 2017
Bearbeitet: Andrei Bobrov am 9 Jun. 2017
A = readtable('A.xls');
B = readtable('B.xls');
na = size(A,1);
nb = size(B,1);
Per1 = sum(ismember(A,B))/na*100;
Per2 = sum(ismember(A{:,1},B{:,1}))/na*100 - Per1;
Per3 = sum(ismember(B,A))/nb*100;
Per4 = sum(ismember(B{:,1},A{:,1}))/nb*100 - Per3;

Weitere Antworten (0)

Kategorien

Mehr zu WSNs finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by