I have two example datasets, A and B below, that I want to join in Matlab to create C. The keys will be ‘product’ and ‘year’, but the problem is that the product number in dataset B only matches the one in A by the first 4 digits. Is there a way to join ‘almost’ matching numbers in this way?
A product tariff year 202341 2 1999 202341 4 2000 202341 20 2008 202355 9 1999 202355 16 2000 438811 0 1999 438891 8 1999 438891 3 2001 671212 15 2005 671260 10 2005
and
B product avg_tariff year 2023 5,5 1999 2023 10 2000 2023 20 2008 4388 4 1999 4388 3 2001 6712 12,5 2005
are joined to produce matrix C
C product tariff year avg_tariff 202341 2 1999 5,5 202341 4 2000 10 202341 20 2008 20 202355 9 1999 5,5 202355 16 2000 10 438811 0 1999 4 438891 8 1999 4 438891 3 2001 3 671212 15 2005 12,5 671260 10 2005 12,5
Thanks in advance
Oscar
load the product array and treat it as strings using textscan:
keep only the first 4 chars of product in A
now just find matches between rowKeyA and rowKeyB