MATLAB Programming Language by K. Parker
Author:K. Parker
Language: eng
Format: epub
Publisher: UNKNOWN
Published: 2016-10-14T23:00:00+00:00
Examples of Functions that Return a Logical Result
MATLAB functions that test the state of a variable or expression return alogicalresult:
A = isstrprop('abc123def', 'alpha') A=
111 00011 1
Logical functions such as xorreturn a logical result:
xor([1 0 'ab' 2.4], [ 0 0 'ab', 0]) ans =
Note however that the bitwise operators do not return a logical:
X = bitxor(3, 12);
whos X
Name Size Bytes Class Attributes
X 1x1 8 double
String comparison functions also return a logical: S = 'D:\matlab\mfiles\test19.m'; strncmp(S, 'D:\matlab', 9) ans =
1 Note the difference between the elementwise and short-circuit logical operators. Short-circuit operators, such as &&and ||, test only as much of the input expression as necessary. In the second part of this example, it makes no difference that Bis undefined because the state of Aalone determines that the expression is false:
A= 0;
A&B
Undefined function or variable 'B'.
A&&B ans =
0
One way of implementing an infinite loop is to use the whilefunction along with the logical constant true: while true
a = []; b = [];
a = input('Enter username: ', 's');
if ~isempty(a)
b = input('Enter password: ', 's'); end
if ~isempty(b) disp 'Attempting to log in to account ...' break
end
end
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6412)
Weapons of Math Destruction by Cathy O'Neil(6224)
Factfulness: Ten Reasons We're Wrong About the World – and Why Things Are Better Than You Think by Hans Rosling(4718)
A Mind For Numbers: How to Excel at Math and Science (Even If You Flunked Algebra) by Barbara Oakley(3266)
Descartes' Error by Antonio Damasio(3253)
Factfulness_Ten Reasons We're Wrong About the World_and Why Things Are Better Than You Think by Hans Rosling(3218)
TCP IP by Todd Lammle(3162)
Fooled by Randomness: The Hidden Role of Chance in Life and in the Markets by Nassim Nicholas Taleb(3084)
Applied Predictive Modeling by Max Kuhn & Kjell Johnson(3047)
The Tyranny of Metrics by Jerry Z. Muller(3035)
The Book of Numbers by Peter Bentley(2945)
The Great Unknown by Marcus du Sautoy(2667)
Once Upon an Algorithm by Martin Erwig(2629)
Easy Algebra Step-by-Step by Sandra Luna McCune(2608)
Lady Luck by Kristen Ashley(2559)
Practical Guide To Principal Component Methods in R (Multivariate Analysis Book 2) by Alboukadel Kassambara(2520)
Police Exams Prep 2018-2019 by Kaplan Test Prep(2520)
All Things Reconsidered by Bill Thompson III(2375)
Linear Time-Invariant Systems, Behaviors and Modules by Ulrich Oberst & Martin Scheicher & Ingrid Scheicher(2350)