1

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?

user36800
  • 2,019
  • 2
  • 19
  • 34

1 Answers1

2

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'})
mcfenelon
  • 106
  • 2
  • Thank you, mcfenelon. TMW said the same. For the sake of consistency with the other join operations, the person helping me submitted a request to have `innerjoin` work with tables containig `OptimizationVariable` fields. – user36800 Jun 29 '19 at 13:33