Any one experienced similar issue?

132 views
Skip to first unread message

a2012

unread,
Sep 1, 2014, 6:15:53 AM9/1/14
to yal...@googlegroups.com
these two examples worked with me before on Matlab 2009 but now they are not working on Matlab 2013a:

x=sdpvar(4,5);

z=sdpvar(4,3);

 y=sdpvar(2,5);

 x(2:end)=0;

 x(:,[1;2;3])=z;

 x(3:4,:)+y


 Error in  +  (line 161)

                all_lmi_variables = [X.lmi_variables Y.lmi_variables]; 


x=sdpvar(4,5);

z=sdpvar(4,3);

y=sdpvar(2,5);

idx=ones(4,5);

idx(10)=0;

x(logical(idx))=0;

x(:,[1;2;3])=z;

x(3:4,:)+y

 

Error in  +  (line 161)

                all_lmi_variables = [X.lmi_variables Y.lmi_variables]; 

Johan Löfberg

unread,
Sep 1, 2014, 6:17:18 AM9/1/14
to yal...@googlegroups.com
Which YALMIP version? Works here...

a2012

unread,
Sep 1, 2014, 6:43:19 AM9/1/14
to yal...@googlegroups.com
last one. 

I have also this code that used to work for me before:

x=sdpvar(2,3)
x(2,:)=[1 2 3]

Error using sdpvar/subsasgn (line 273)
Error using sub2ind (line 52)
Out of range subscript.

a2012

unread,
Sep 1, 2014, 6:47:11 AM9/1/14
to yal...@googlegroups.com
these results are from Matlab 2013b not 2013a as I said before.

Johan Löfberg

unread,
Sep 1, 2014, 7:14:01 AM9/1/14
to yal...@googlegroups.com
Sorry I was running the develop version where this is already fixed. Change line 104 in sdpvar/subsasgn to I.subs{2} = 1:m;


a2012

unread,
Sep 1, 2014, 8:10:08 AM9/1/14
to yal...@googlegroups.com
thanks a lot. 

changing line 104 in subsasgn fixes the problem in x(2,:)=[1 2 3] .

but unfortunately it did not fix the two issues mentioned in the original post. 

what is happening in the two examples above is that X.lmi_variables (in plus function) will be defined as column vectors which causes horzcat issue in line 161.


Johan Löfberg

unread,
Sep 1, 2014, 8:13:12 AM9/1/14
to yal...@googlegroups.com
replace
subsasgn.m

a2012

unread,
Sep 1, 2014, 8:28:11 AM9/1/14
to yal...@googlegroups.com
Sorry the two examples in the original post still give the same error.

Error using horzcat
Dimensions of matrices being concatenated are not consistent.

Error in  +  (line 160)
                all_lmi_variables = [X.lmi_variables Y.lmi_variables];

Johan Löfberg

unread,
Sep 1, 2014, 8:36:42 AM9/1/14
to yal...@googlegroups.com
You cannot have replaced the file as line 160 doesn't look like that in the new @sdpvar/subsasgn.m I attached

Johan Löfberg

unread,
Sep 1, 2014, 8:43:14 AM9/1/14
to yal...@googlegroups.com
Sorry, got a bit confused here as there appears to be two completely different issues. I cannot reproduce the problem with the plus operator, will have to play around a bit

Johan Löfberg

unread,
Sep 1, 2014, 8:59:22 AM9/1/14
to
This one should work in all matlab versions.

Thank you for alerting me.

FYI, the underlying problem is that MATLAB R2013 and later appears to return weird dimensions in union

R2012
 union([],[1 2 3])

union([1],[1 2 3])

ans
=

     
1     2     3


ans
=

     
1     2     3


R2014
union([],[1 2 3])

ans =

     1
     2
     3

K>> union([1],[1 2 3])

ans =

     1     2     3




subsasgn.m

a2012

unread,
Sep 1, 2014, 10:10:09 AM9/1/14
to yal...@googlegroups.com
thanks a lot. this fixes the problem.

:)



Mark L. Stone

unread,
Sep 1, 2014, 10:21:32 AM9/1/14
to yal...@googlegroups.com
Johan wrote "FYI, the underlying problem is that MATLAB R2013 and later appears to return weird dimensions in union"

As it turns out, it's not a bug, it's a feature.  Per help union:
    The behavior of union has changed.  This includes:
      -    occurrence of indices in IA and IB switched from last to first
      -    orientation of vector C
      -    IA and IB will always be column index vectors
      -    tighter restrictions on combinations of classes
 
    If this change in behavior has adversely affected your code, you may
    preserve the previous behavior with:
 
       [C,IA,IB] = union(A,B,'legacy')
       [C,IA,IB] = union(A,B,'rows','legacy')
Reply all
Reply to author
Forward
0 new messages