简体   繁体   中英

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?

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              

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM