Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MATLAB can I convert a java boolean to a MATLAB logical?

In MATLAB I'm using a couple of java routines I've written to interface with a MyQSL database. One routine returns a boolean value

result  <1x1 java.lang.Boolean>
>> result 
result =
true

When I then use it in a conditional statement I get an error message.

>> if result,
disp('result is true')
end
??? Conversion to logical from java.lang.Boolean is not possible.

Is there a way to use the java boolean class as a MATLAB logical type? Or do I have to resort to returning integer values from my java routines?

like image 872
Adrian Avatar asked Mar 16 '10 12:03

Adrian


People also ask

How do you create a logical in Matlab?

L = logical( A ) converts A into an array of logical values. Any nonzero element of A is converted to logical 1 ( true ) and zeros are converted to logical 0 ( false ). Complex values and NaNs cannot be converted to logical values and result in a conversion error.

How do you define a logical variable in Matlab?

-by- szN array of logical ones where sz1,...,szN indicates the size of each dimension. For example, true(2,3) returns a 2-by-3 array of logical ones. T = true(___,'like', p ) returns an array of logical ones of the same sparsity as the logical variable p using any of the previous size syntaxes.


1 Answers

Example:

b = java.lang.Boolean(true);

if b.booleanValue
    disp('val is true')
else
    disp('val is false')
end

And to make sure:

>> v = b.booleanValue;
>> whos v
  Name      Size            Bytes  Class      Attributes

  v         1x1                 1  logical              
like image 151
Amro Avatar answered Oct 04 '22 19:10

Amro