gpt4 book ai didi

matlab - boolean 值和逻辑值之间的区别

转载 作者:太空宇宙 更新时间:2023-11-03 19:13:10 24 4
gpt4 key购买 nike

出于好奇,如果我在 MATLAB 中输入这些行:

a = logical([12 0 1.2]);
b = boolean([12 0 1.2]);

输出变量ab 是相同的(相同的值和类型)。因此,booleanlogical 之间有什么区别吗?

最佳答案

快速浏览一下 boolean 函数可以很好地回答您的问题:

如果您在 matlab 控制台中键入:edit boolean,您将获得:

function y = boolean(x)
%BOOLEAN Creates a boolean vector.
% This function is typically used in Simulink parameter dialogs, such as
% the Constant block dialog. This function generates a logical vector,
% which is treated as a boolean value in Simulink. Now that logical is a
% MATLAB type, this function is essentially just an alias.
%
% Y = BOOLEAN(X) Converts the vector X into a boolean vector.
%
% Example:
% boolean([0 1 1]) returns [0 1 1]
%
% See also LOGICAL.

% Copyright 1990-2012 The MathWorks, Inc.

narginchk(1,1);

if ~isreal(x)
DAStudio.error('Simulink:utility:BooleanCannotBeComplex');
end

y = logical(x);

如果您查看此函数的最后一行,您会发现 boolean 函数调用了逻辑函数。

关于matlab - boolean 值和逻辑值之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22045291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com