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:
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:
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));
相关文章推荐
- aotu modify table ' field's value,by ODBC directly is false,but use CDatabase can well and also the header file is needed.
- Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead
- What values should I use for iOS boolean states?该不该使用true和false作为bool值
- The use of functions
- How and Why to use the System.servicemodel.MessageParameterAttribute in WCF
- the command 'vim' and how to use it
- how to use a SQLite database in a standalone program with an HTML interface and VBScript as the programming language
- FW:Use the OnReadyStateChange Property in Visual Basic and Visual C/C++
- The most simple and easy to use Qt GUI library plug-in FTStyle (1)
- 20 reasons to shed the Microsoft yoke and use Linux
- 117.Which statements are true regarding the WHERE and HAVING clauses in a SELECT statement?
- Effective Java 47 Know and use the libraries
- Describe 3 kernel functions and when to use which of them
- TextView with SingleLine as true and Gravity as Center not passing the events to the ViewPager if it has a Click Event
- The unit impulse and step functions in continuous time
- Mysql:You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true
- Use the PDFs below or the HTML contents to the left to install and configure P6 EPPM and its additional components.
- Could I use NEON and VFP at the same time in my application?
- Use C# to get JSON Data from the Web and Map it to .NET Class => Made Easy! 转