Custom function with Mulidimensional Arguments

38 views
Skip to first unread message

Jonathan Scarlett

unread,
Apr 15, 2013, 8:24:04 AM4/15/13
to yal...@googlegroups.com
Hi,

I'm trying to write a function using the Evaluation-Based Representations framework.  The basic structure of the file is standard:

switch class(varargin{1})
case 'double'
    ...
case 'sdpvar'
    varargout{1} = yalmip('define',mfilename,varargin{:});
case 'char'
    ...

I tried calling the code with a 2x2x2 sdpvar, and it didn't match any of the cases.  I then noticed that the class was in fact "ndsdpvar", so I added 

case 'ndsdpvar'
    varargin{:}
    varargout{1} = yalmip('define',mfilename,varargin{:});

However, this gives the error

??? The following error occurred converting from constraint to logical:
Error using ==> logical
Conversion to logical from constraint is not possible.

Error in ==> yalmip at 169
                if this_hash == internal_sdpvarstate.ExtendedMap(i).Hash

Can the code be adapted to handle multi-dimensional SDPVAR objects?

Thanks.

Johan Löfberg

unread,
Apr 15, 2013, 11:03:26 AM4/15/13
to yal...@googlegroups.com
I will look into it, but in the mean time, maybe you can reshape your argument before sending it, and then reshape back (assuming element-wise operator)
 
switch class(varargin{1})
case 'double'
...
case 'sdpvar'
    d = size(varargin{1};
    varargin{1} = reshape(varargin{1},[],1);
    y = yalmip('define',mfilename,varargin{:});
    varargout{1} = reshape(y,d);
case 'char'

Jonathan Scarlett

unread,
Apr 15, 2013, 12:39:10 PM4/15/13
to yal...@googlegroups.com
I'm happy with the 'reshape' solution, thanks!
Reply all
Reply to author
Forward
0 new messages