comparing between two cell arrays

4 ビュー (過去 30 日間)
Salma fathi
Salma fathi 2022 年 12 月 11 日
コメント済み: Star Strider 2022 年 12 月 15 日
we have two cell arrays that we would like to compare. the first of size 3x67 call it A and the second is of size 3x2 call it B. each row of the two cell arrays represent the data for the same day so we would like to compare the cells in the first row of A by the cell in the first row of B and so on. we are looking after the columnS "fof2" and "hmf2" from the cell in B, we will check the timimg in hours and minutes from the Date columns between this cell and the cells in A, and add to each cell in A the corresponding data for the columns "fof2" and "hmf2", it is not neccesary that we find exactly matching timings it is enough for them to be with in +-15mins range from each other. I am having an issue with the comparison between cell arrays, so if anyoe can help me in finding an effecient and easy way to do this, I attach the two cell array that I am working with.
Thanks in advance.

採用された回答

Star Strider
Star Strider 2022 年 12 月 11 日
I am not certain what result you want.
Try this, and if it works, loop through the elements of ‘A’ and ‘B’ for all the necessary combinations. Note that in at least one for the ‘B’ table, ‘hmF2’ is actually 'hmF2 ' with an extra space that creates problems with the variable name referencing. If all the resulting timetables have the same variables in the same locations, numerical referencing will work.
LD = load(websave('A&B','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1227457/A&B.mat'))
LD = struct with fields:
A: {3×67 cell} B: {3×2 cell}
A = LD.A
A = 3×67 cell array
{[254]} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} {[255]} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {103×9 table } {[256]} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} {103×9 table} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double} { 0×0 double}
B = LD.B
B = 3×2 cell array
{[254]} {63×10 table} {[255]} {20×10 table} {[256]} {22×10 table}
A12 = A{1,2}
A12 = 103×9 table
YEAR MONTH DAY HOUR MIN GDALT NE8 Date DoY ____ _____ ___ ____ ___ _____ _________ ________________ ___ 2007 9 11 15 20 105 NaN 2007-09-11-15:20 254 2007 9 11 15 20 120 NaN 2007-09-11-15:20 254 2007 9 11 15 20 135 6.7e+11 2007-09-11-15:20 254 2007 9 11 15 20 150 1.789e+12 2007-09-11-15:20 254 2007 9 11 15 20 165 3.58e+11 2007-09-11-15:20 254 2007 9 11 15 20 180 1.95e+11 2007-09-11-15:20 254 2007 9 11 15 20 195 1.9e+11 2007-09-11-15:20 254 2007 9 11 15 20 210 2.07e+11 2007-09-11-15:20 254 2007 9 11 15 20 225 2.35e+11 2007-09-11-15:20 254 2007 9 11 15 20 240 2.64e+11 2007-09-11-15:20 254 2007 9 11 15 20 255 2.87e+11 2007-09-11-15:20 254 2007 9 11 15 20 270 3.08e+11 2007-09-11-15:20 254 2007 9 11 15 20 285 3.34e+11 2007-09-11-15:20 254 2007 9 11 15 20 300 3.66e+11 2007-09-11-15:20 254 2007 9 11 15 20 315 3.69e+11 2007-09-11-15:20 254 2007 9 11 15 20 330 3.69e+11 2007-09-11-15:20 254
A12 = A12(:,[8 1:7 9])
A12 = 103×9 table
Date YEAR MONTH DAY HOUR MIN GDALT NE8 DoY ________________ ____ _____ ___ ____ ___ _____ _________ ___ 2007-09-11-15:20 2007 9 11 15 20 105 NaN 254 2007-09-11-15:20 2007 9 11 15 20 120 NaN 254 2007-09-11-15:20 2007 9 11 15 20 135 6.7e+11 254 2007-09-11-15:20 2007 9 11 15 20 150 1.789e+12 254 2007-09-11-15:20 2007 9 11 15 20 165 3.58e+11 254 2007-09-11-15:20 2007 9 11 15 20 180 1.95e+11 254 2007-09-11-15:20 2007 9 11 15 20 195 1.9e+11 254 2007-09-11-15:20 2007 9 11 15 20 210 2.07e+11 254 2007-09-11-15:20 2007 9 11 15 20 225 2.35e+11 254 2007-09-11-15:20 2007 9 11 15 20 240 2.64e+11 254 2007-09-11-15:20 2007 9 11 15 20 255 2.87e+11 254 2007-09-11-15:20 2007 9 11 15 20 270 3.08e+11 254 2007-09-11-15:20 2007 9 11 15 20 285 3.34e+11 254 2007-09-11-15:20 2007 9 11 15 20 300 3.66e+11 254 2007-09-11-15:20 2007 9 11 15 20 315 3.69e+11 254 2007-09-11-15:20 2007 9 11 15 20 330 3.69e+11 254
B12 = B{1,2}
B12 = 63×10 table
Date CS foF2 foF1 foEs foE hmE hmF2 hmF1 DoY ___________________ ___ ____ _____ ____ ___ ___ _____ _____ ___ 11-09-2007 00:00:00 999 4.8 NaN NaN NaN NaN 350.3 NaN 254 11-09-2007 00:15:00 999 4.4 NaN NaN NaN NaN 302.4 NaN 254 11-09-2007 00:30:00 0 4.6 NaN NaN NaN 110 NaN NaN 254 11-09-2007 01:00:00 100 4.6 NaN NaN NaN 110 297.5 NaN 254 11-09-2007 01:15:00 100 4.3 NaN NaN NaN 110 264.1 NaN 254 11-09-2007 01:30:03 100 4.5 NaN NaN NaN 110 269.7 NaN 254 11-09-2007 01:45:02 100 4.6 NaN NaN NaN 110 286.4 NaN 254 11-09-2007 02:00:00 100 4.7 NaN NaN NaN 110 277.6 NaN 254 11-09-2007 02:15:00 100 4.4 NaN NaN NaN 110 272.6 NaN 254 11-09-2007 02:30:00 100 3.4 NaN NaN NaN 110 224.7 NaN 254 11-09-2007 02:45:00 100 4.6 NaN NaN NaN 110 271.7 NaN 254 11-09-2007 03:00:00 100 5.7 NaN NaN NaN 110 276 NaN 254 11-09-2007 03:15:00 100 5.8 NaN NaN NaN 110 275.3 NaN 254 11-09-2007 03:30:00 100 5.7 NaN NaN NaN 110 253.6 NaN 254 11-09-2007 03:45:00 100 4.2 NaN NaN NaN 110 245.4 NaN 254 11-09-2007 04:00:00 100 5.8 NaN NaN NaN 110 270.6 NaN 254
TTA12 = table2timetable(A12)
TTA12 = 103×8 timetable
Date YEAR MONTH DAY HOUR MIN GDALT NE8 DoY ________________ ____ _____ ___ ____ ___ _____ _________ ___ 2007-09-11-15:20 2007 9 11 15 20 105 NaN 254 2007-09-11-15:20 2007 9 11 15 20 120 NaN 254 2007-09-11-15:20 2007 9 11 15 20 135 6.7e+11 254 2007-09-11-15:20 2007 9 11 15 20 150 1.789e+12 254 2007-09-11-15:20 2007 9 11 15 20 165 3.58e+11 254 2007-09-11-15:20 2007 9 11 15 20 180 1.95e+11 254 2007-09-11-15:20 2007 9 11 15 20 195 1.9e+11 254 2007-09-11-15:20 2007 9 11 15 20 210 2.07e+11 254 2007-09-11-15:20 2007 9 11 15 20 225 2.35e+11 254 2007-09-11-15:20 2007 9 11 15 20 240 2.64e+11 254 2007-09-11-15:20 2007 9 11 15 20 255 2.87e+11 254 2007-09-11-15:20 2007 9 11 15 20 270 3.08e+11 254 2007-09-11-15:20 2007 9 11 15 20 285 3.34e+11 254 2007-09-11-15:20 2007 9 11 15 20 300 3.66e+11 254 2007-09-11-15:20 2007 9 11 15 20 315 3.69e+11 254 2007-09-11-15:20 2007 9 11 15 20 330 3.69e+11 254
TTB12 = table2timetable(B12)
TTB12 = 63×9 timetable
Date CS foF2 foF1 foEs foE hmE hmF2 hmF1 DoY ___________________ ___ ____ _____ ____ ___ ___ _____ _____ ___ 11-09-2007 00:00:00 999 4.8 NaN NaN NaN NaN 350.3 NaN 254 11-09-2007 00:15:00 999 4.4 NaN NaN NaN NaN 302.4 NaN 254 11-09-2007 00:30:00 0 4.6 NaN NaN NaN 110 NaN NaN 254 11-09-2007 01:00:00 100 4.6 NaN NaN NaN 110 297.5 NaN 254 11-09-2007 01:15:00 100 4.3 NaN NaN NaN 110 264.1 NaN 254 11-09-2007 01:30:03 100 4.5 NaN NaN NaN 110 269.7 NaN 254 11-09-2007 01:45:02 100 4.6 NaN NaN NaN 110 286.4 NaN 254 11-09-2007 02:00:00 100 4.7 NaN NaN NaN 110 277.6 NaN 254 11-09-2007 02:15:00 100 4.4 NaN NaN NaN 110 272.6 NaN 254 11-09-2007 02:30:00 100 3.4 NaN NaN NaN 110 224.7 NaN 254 11-09-2007 02:45:00 100 4.6 NaN NaN NaN 110 271.7 NaN 254 11-09-2007 03:00:00 100 5.7 NaN NaN NaN 110 276 NaN 254 11-09-2007 03:15:00 100 5.8 NaN NaN NaN 110 275.3 NaN 254 11-09-2007 03:30:00 100 5.7 NaN NaN NaN 110 253.6 NaN 254 11-09-2007 03:45:00 100 4.2 NaN NaN NaN 110 245.4 NaN 254 11-09-2007 04:00:00 100 5.8 NaN NaN NaN 110 270.6 NaN 254
TTAB12 = synchronize(TTA12,TTB12)
TTAB12 = 64×17 timetable
Date YEAR MONTH DAY HOUR MIN GDALT NE8 DoY_TTA12 CS foF2 foF1 foEs foE hmE hmF2 hmF1 DoY_TTB12 ________________ ____ _____ ___ ____ ___ _____ ___ _________ ___ ____ _____ ____ ___ ___ _____ _____ _________ 2007-09-11-00:00 NaN NaN NaN NaN NaN NaN NaN NaN 999 4.8 NaN NaN NaN NaN 350.3 NaN 254 2007-09-11-00:15 NaN NaN NaN NaN NaN NaN NaN NaN 999 4.4 NaN NaN NaN NaN 302.4 NaN 254 2007-09-11-00:30 NaN NaN NaN NaN NaN NaN NaN NaN 0 4.6 NaN NaN NaN 110 NaN NaN 254 2007-09-11-01:00 NaN NaN NaN NaN NaN NaN NaN NaN 100 4.6 NaN NaN NaN 110 297.5 NaN 254 2007-09-11-01:15 NaN NaN NaN NaN NaN NaN NaN NaN 100 4.3 NaN NaN NaN 110 264.1 NaN 254 2007-09-11-01:30 NaN NaN NaN NaN NaN NaN NaN NaN 100 4.5 NaN NaN NaN 110 269.7 NaN 254 2007-09-11-01:45 NaN NaN NaN NaN NaN NaN NaN NaN 100 4.6 NaN NaN NaN 110 286.4 NaN 254 2007-09-11-02:00 NaN NaN NaN NaN NaN NaN NaN NaN 100 4.7 NaN NaN NaN 110 277.6 NaN 254 2007-09-11-02:15 NaN NaN NaN NaN NaN NaN NaN NaN 100 4.4 NaN NaN NaN 110 272.6 NaN 254 2007-09-11-02:30 NaN NaN NaN NaN NaN NaN NaN NaN 100 3.4 NaN NaN NaN 110 224.7 NaN 254 2007-09-11-02:45 NaN NaN NaN NaN NaN NaN NaN NaN 100 4.6 NaN NaN NaN 110 271.7 NaN 254 2007-09-11-03:00 NaN NaN NaN NaN NaN NaN NaN NaN 100 5.7 NaN NaN NaN 110 276 NaN 254 2007-09-11-03:15 NaN NaN NaN NaN NaN NaN NaN NaN 100 5.8 NaN NaN NaN 110 275.3 NaN 254 2007-09-11-03:30 NaN NaN NaN NaN NaN NaN NaN NaN 100 5.7 NaN NaN NaN 110 253.6 NaN 254 2007-09-11-03:45 NaN NaN NaN NaN NaN NaN NaN NaN 100 4.2 NaN NaN NaN 110 245.4 NaN 254 2007-09-11-04:00 NaN NaN NaN NaN NaN NaN NaN NaN 100 5.8 NaN NaN NaN 110 270.6 NaN 254
VN = TTAB12.Properties.VariableNames
VN = 1×17 cell array
{'YEAR'} {'MONTH'} {'DAY'} {'HOUR'} {'MIN'} {'GDALT'} {'NE8'} {'DoY_TTA12'} {'CS'} {'foF2'} {'foF1 '} {'foEs'} {'foE'} {'hmE'} {'hmF2 '} {'hmF1 '} {'DoY_TTB12'}
VN{15}
ans = 'hmF2 '
TTAB12_Result = TTAB12(:,[10 15])
TTAB12_Result = 64×2 timetable
Date foF2 hmF2 ________________ ____ _____ 2007-09-11-00:00 4.8 350.3 2007-09-11-00:15 4.4 302.4 2007-09-11-00:30 4.6 NaN 2007-09-11-01:00 4.6 297.5 2007-09-11-01:15 4.3 264.1 2007-09-11-01:30 4.5 269.7 2007-09-11-01:45 4.6 286.4 2007-09-11-02:00 4.7 277.6 2007-09-11-02:15 4.4 272.6 2007-09-11-02:30 3.4 224.7 2007-09-11-02:45 4.6 271.7 2007-09-11-03:00 5.7 276 2007-09-11-03:15 5.8 275.3 2007-09-11-03:30 5.7 253.6 2007-09-11-03:45 4.2 245.4 2007-09-11-04:00 5.8 270.6
.
  4 件のコメント
Salma fathi
Salma fathi 2022 年 12 月 15 日
Thank you so much this helped a lot, exactly what I was looking for. I appreciate all the assisstance. Thank you
Star Strider
Star Strider 2022 年 12 月 15 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by