Union of two tables in MATLAB, only taking rows in one table -


suppose have 2 matlab tables:

>> x = table({'a' 'b' 'c' 'd'}', (1:4)', 'variablenames', {'thekey' 'thevalue'}) x =      thekey    thevalue     ______    ________     'a'       1            'b'       2            'c'       3            'd'       4        >> y = table({'b' 'c'}', [998 999]', 'variablenames', {'thekey' 'thevalue'}) y =      thekey    thevalue     ______    ________     'b'       998           'c'       999    

is there procedure (some type/combination of union/join/outerjoin maybe) returns me union of 2 tables, keeps rows 2nd table if there duplication according key choose (thekey)? example, i'm looking have output:

    thekey    thevalue     ______    ________     'a'       1            'b'       998            'c'       999            'd'       4        

thanks!

if understand question correctly, you're looking @ unioning using outerjoin in matlab. don't think there's way joins, may have play games indexing.

>> b=outerjoin(x,y,'type','left','mergekeys',true,'leftkeys',{'thekey'},'rightkeys',{'thekey'})  ans =       thekey    thevalue_x    thevalue_y     ______    __________    __________      'a'       1             nan            'b'       2             998            'c'       3             999            'd'       4             nan         >> b.(2)(~isnan(b.(3)))=b.(3)(~isnan(b.(3)))      thekey    thevalue_x    thevalue_y     ______    __________    __________      'a'       1             nan            'b'       998           998            'c'       999           999            'd'       4             nan     >> b.(3)=[]      thekey    thevalue_x     ______    __________      'a'         1            'b'       998            'c'       999            'd'         4        

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -