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

2 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2017-6-9
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 2017-6-9
Ok, i have attached my tables... for rows that not included in both .. eliminated .. thanks

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2017-6-9
编辑:Andrei Bobrov 2017-6-9
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 WSNs 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by