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

1 visualización (últimos 30 días)
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 comentarios
Image Analyst
Image Analyst el 9 de Jun. de 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 el 9 de Jun. de 2017
Ok, i have attached my tables... for rows that not included in both .. eliminated .. thanks

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 9 de Jun. de 2017
Editada: Andrei Bobrov el 9 de Jun. de 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;

Más respuestas (0)

Categorías

Más información sobre WSNs en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by