简体   繁体   English

在MATLAB中,我可以将java布尔值转换为MATLAB逻辑吗?

[英]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. 在MATLAB中,我使用了几个我编写的java例程来与MyQSL数据库进行交互。 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? 有没有办法将java boolean类用作MATLAB逻辑类型? Or do I have to resort to returning integer values from my java routines? 或者我是否必须从我的java例程中返回整数值?

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              

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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