Search code examples
matlaboptimizationinner-join

Matlab innerjoin error when table has OptimizationVariable column


I'm running into an error using innerjoin when one of the tables contains a column of OptimizationVariable objects:

% A normal table
tLeft = table([1;2],[3;4],'VariableNames',{'v1' 'v2'})

% A table with a column of `optimvar` objects
tRight = table( [1;2] , optimvar('myvar',2,1) , ...
                'VariableNames',{'v1' 'ov2'})

% `join` works
tJoin = join(tLeft,tRight,'Key','v1')
showexpr(tJoin.ov2)
   % myvar(1)
   % myvar(2)

% `innerjoin` yields error assigning to optimvar object
tJoin = innerjoin(tLeft,tRight)

% Work-around
tJoin = innerjoin(tLeft,tRight,'RightVar',{})
tJoin = join( tJoin , tRight , 'RightVar','ov2' )
showexpr(tJoin.ov2)
   % myvar(1)
   % myvar(2)

Is there a fundamental conceptual flaw behind innerjoining a table containing a OptimizationVariable column, or is this just teething pains in Matlab's new high level optimization workflow?


Solution

  • OptimizationVariable can't be used but OptimizationExpression can be. That gives another work-around: create tRight with expressions instead of variables:

    tRight = table( [1;2] , 1*optimvar('myvar',2,1) , ...
                    'VariableNames',{'v1' 'ov2'})