根据重叠进行比较和排序

Compare and sort based on overlap

我有一个如下所示的元胞数组(截断):

'State Name'                   'State Abbr'    'State Code'    'Region'
-----------------------------------------------------------------------
'Alabama'                      'AL'            '01'            '04'
'Alaska'                       'AK'            '02'            '10'
'Arizona'                      'AZ'            '04'            '09'
'Arkansas'                     'AR'            '05'            '06'
'California'                   'CA'            '06'            '09'
'Canada'                       'CC'            'CC'            '25'
'Colorado'                     'CO'            '08'            '08'
'Connecticut'                  'CT'            '09'            '01'
'Country Of Mexico'            'MX'            '80'            '25'
'Delaware'                     'DE'            '10'            '03'
'Delaware'                     'DE'            '10'            '03'
'Florida'                      'FL'            '12'            '04'
'Georgia'                      'GA'            '13'            '04'

我有另一个数组,看起来像这样(截断):

      MonitorID         POC    Latitude    Longitude     Datum           ParameterName           SampleDuration
___________________    ___    ________    _________    _______    __________________________    _______________

'01-073-0023-88101'    '1'    33.553      -86.815      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'01-073-0023-88101'    '1'    33.553      -86.815      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'01-073-0023-88101'    '1'    33.553      -86.815      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'01-073-0023-88101'    '1'    33.553      -86.815      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'01-073-0023-88101'    '1'    33.553      -86.815      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'02-170-0013-88101'    '1'    61.599      -149.46      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'02-170-0013-88101'    '1'    61.599      -149.46      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'02-170-0013-88101'    '1'    61.599      -149.46      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'02-170-0013-88101'    '1'    61.599      -149.46      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'02-170-0013-88101'    '1'    61.599      -149.46      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'02-170-0013-88101'    '1'    61.599      -149.46      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'02-170-0013-88101'    '1'    61.599      -149.46      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'02-170-0013-88101'    '1'    61.599      -149.46      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'
'02-170-0013-88101'    '1'    61.599      -149.46      'WGS84'    'PM2.5 - Local Conditions'    '24 HOUR'

我想做的是根据第一个数组的区域代码对第二个数组(实际上有更多的行和列)进行排序。

现在,第二个数组确实有区域代码。但是,它确实有州代码。州代码是 MonitorID 列中的前两个数字。例如,对于“01-073-0023-88101”,州代码为“01”。我需要在第二个数组中找到每个州代码并将其与第一个数组中给出的正确区域相匹配。然后,我需要按区域代码对第二个数组进行排序。

我该怎么做?我不确定如何将第二个数组的前两个数字与第一个数组的第 3 列进行比较并为其分配新区域。完成这些步骤后,对其进行排序应该不会太困难。

假设 AB 分别是第一个和第二个数组,这将是一种方法 -

%// Split the first column of B with "-" as the delimiter
Bcol1_split = cellfun(@(x) strsplit(x,'-'),B(:,1),'Uni',0)

%// Extract the first split string which would be the state codes
Bcol1_first_string = cellfun(@(x) x{1},Bcol1_split,'Uni',0)

%// Detect IDs of matching state codes from from B to those in A 
[~,matched_ID] = ismember(Bcol1_first_string,A(:,3))

%// Use those IDs to get corresponding Region codes for each row of data in B
mapped_region_codes = A(matched_ID,4)

%// Sort the region codes to get the IDs based on which B is to be
%// row-indexed, which would be the final output
[~,sorted_mapped_IDs] =  sort(mapped_region_codes)
outB = B(sorted_mapped_IDs,:)