您的位置:首页 > 产品设计 > UI/UE

20060315-Quick tip: Use the functions true and false

2014-05-07 10:05 337 查看
原文:http://blogs.mathworks.com/steve/2006/03/15/quick-tip-use-the-functions-true-and-false/

I saw some code recently that looked something like this:

B = zeros(size(A));
B = logical(B);


The intent of the code was to initialize an all-zero binary image with the same size as
A. Note, however, that the output of the zeros function in the first line is a double-precision array, which requires
eight bytes per element. Logical arrays in MATLAB, on the other hand, use
only one byte per element. It's quicker and more memory efficient to initialize B using the
false function.

The functions true and
false are most often seen without input arguments, in which case they return a scalar logical 1 or a scalar logical 0, respectively. But they also support an optional size input. So the following code works just as well for initializing the
binary image:

B = false(size(A));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐