changeset 20750:fdffc955b4ed stable

doc: Clarify how if statement determines true or false for a matrix input. * stmt.txi: Clarify how if statement determines true or false for a matrix input.
author Rik <rik@octave.org>
date Tue, 24 Nov 2015 17:21:47 -0800
parents ab0d9d7f479c
children a0655d18c9cc
files doc/interpreter/stmt.txi
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/stmt.txi	Fri Nov 20 11:37:48 2015 +0100
+++ b/doc/interpreter/stmt.txi	Tue Nov 24 17:21:47 2015 -0800
@@ -86,8 +86,14 @@
 is nonzero, and false if its value is zero.  If the value of the
 conditional expression in an @code{if} statement is a vector or a
 matrix, it is considered true only if it is non-empty and @emph{all}
-of the elements are nonzero.
+of the elements are nonzero.  The conceptually equivalent code when
+@var{condition} is a matrix is shown below.
 
+@example
+if (@var{matrix}) @equiv{} if (all (@var{matrix}(:)))
+@end example
+
+@noindent
 The second form of an if statement looks like this:
 
 @example
@@ -589,9 +595,8 @@
 
 @noindent
 In the above case, the multi-dimensional matrix @var{c} is reshaped to a
-two-dimensional matrix as @code{reshape (c, rows (c),
-prod (size (c)(2:end)))} and then the same behavior as a loop over a two
-dimensional matrix is produced.
+two-dimensional matrix as @code{reshape (c, rows (c), prod (size (c)(2:end)))}
+and then the same behavior as a loop over a two dimensional matrix is produced.
 
 Although it is possible to rewrite all @code{for} loops as @code{while}
 loops, the Octave language has both statements because often a