"NaN's cannot be converted to logicals." displayed when I use symbol "|" in my constraints.

977 views
Skip to first unread message

李汇熙

unread,
Mar 17, 2015, 4:44:41 AM3/17/15
to yal...@googlegroups.com
Hi Johan
I tried to use exressions like sum(x1|x2) as constraint, but yalmip told me that
 "Error using  | 
NaN's cannot be converted to logicals."
in which x1 and x2 are n*1 matrices and their elements are 0 or 1.
What should I do to handle this?
Thx!


Johan Löfberg

unread,
Mar 17, 2015, 4:49:04 AM3/17/15
to yal...@googlegroups.com
Please supply a reproducible example

Johan Löfberg

unread,
Mar 17, 2015, 5:10:34 AM3/17/15
to yal...@googlegroups.com
BTW, sounds like this has nothing to do with YALMIP and you are simply evaluating incorrect expressions in MATLAB

>> sum(nan | 1)

李汇熙

unread,
Mar 17, 2015, 6:04:34 AM3/17/15
to yal...@googlegroups.com
I've no idea about this because I believe I've initiallized all related variables.
So please check my code and help me to find out what my errors really are.
I use generate_data.m to create a dataset, then run vmpack.m. All "|" operations are in Sum_of_U.
Thx!
generate_data.m
Sum_of_U.m
vmpack.m

Johan Löfberg

unread,
Mar 17, 2015, 6:13:59 AM3/17/15
to yal...@googlegroups.com
>> generate_data
Undefined function 'matrix_2' for input arguments of type 'double'.

Error in generate_data (line 21)
VM1
= [matrix_2(block_unique, g_vm,1);
 
>> vmpack
Undefined function or variable 'vc'.

Error in vmpack (line 5)
constraints
= [vc*X<=pc, vm*X<=pm, sum(X,2)==1,];
 


李汇熙

unread,
Mar 17, 2015, 6:28:36 AM3/17/15
to yal...@googlegroups.com
I'm very sorry about that.
Ignore generate_datea.m plz, load this matlab.mat.
matlab.mat

Johan Löfberg

unread,
Mar 17, 2015, 6:38:33 AM3/17/15
to yal...@googlegroups.com
You evaluate a value of X before you solve anything, hence it sends NaNs to Sum_of_U

Sum_of_U(value(X),M,C1)


李汇熙

unread,
Mar 17, 2015, 7:14:05 AM3/17/15
to yal...@googlegroups.com
yes, thanks for your hint!
It works when I use Sum_of_U(X,M,C1).
Reply all
Reply to author
Forward
0 new messages