annotate scripts/strings/mat2str.m @ 33624:e0c037a01fde default tip

redirect stdout and stderr into experimental terminal widget * command-widget.cc (command_widget): open temp files for redirecting stdout and stderr, setup a file system watcher for signals on changes to these files; (~command_widget): close and remove the temp. files; (insert_interpreter_output): use the style as second argument (print_stream): add new contents of temp. files for stdout and stderr to the end of the terminal contents; (notice_settings): set the terminal preferences to the new lexer of the console; (console): create and set new lexer; (new_command_line): use prompt style for the prompt; (execute_command): use second command line argument for the style; (append_string): use style as second argument and style the added text accordingly; * command-widget.h (console) append_string with second argument for style, (command_widget): now with destructor, new method print_stream, insert_interpreter_output with second argument for style, new class variables for temp. file descriptors and file system watcher * console-lexer.cc/h: new lexer derived from QScintillas default lexer for styling the terminal output, styles used so far: Default, Error, and Prompt * gui-preferences-cs.h: new constants for error and prompt colors * libgui/src/module.mk: new files console_lexer.cc/h * qt-interpreter-events.cc (display_exception): interpreter_output_signal with second argument for the style, here Error style * qt-interpreter-events.h: interpreter_output_signal with second argument for the style * terminal-dock-widget.h: interpreter_output_signal with second argument for the style
author Torsten Lilge <ttl-octave@mailbox.org>
date Sat, 25 May 2024 14:36:01 +0200
parents 2e484f9f1f18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 ## Copyright (C) 2002-2024 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27680
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
7 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
14 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
19 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
25
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
27 ## @deftypefn {} {@var{s} =} mat2str (@var{x}, @var{n})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
28 ## @deftypefnx {} {@var{s} =} mat2str (@var{x}, @var{n}, "class")
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ## Format real, complex, and logical matrices as strings.
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ##
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
31 ## The returned string may be used to reconstruct the original matrix by using
13314
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
32 ## the @code{eval} function.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
33 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
34 ## The precision of the values is given by @var{n}. If @var{n} is a scalar
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
35 ## then both real and imaginary parts of the matrix are printed to the same
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
36 ## precision. Otherwise @code{@var{n}(1)} defines the precision of the real
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20164
diff changeset
37 ## part and @code{@var{n}(2)} defines the precision of the imaginary part.
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
38 ## The default for @var{n} is 15.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
39 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16994
diff changeset
40 ## If the argument @qcode{"class"} is given then the class of @var{x} is
13180
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
41 ## included in the string in such a way that @code{eval} will result in the
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
42 ## construction of a matrix of the same class.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
43 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
44 ## @example
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
45 ## @group
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8442
diff changeset
46 ## mat2str ([ -1/3 + i/7; 1/3 - i/7 ], [4 2])
8442
502e58a0d44f Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7812
diff changeset
47 ## @result{} "[-0.3333+0.14i;0.3333-0.14i]"
502e58a0d44f Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7812
diff changeset
48 ##
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8442
diff changeset
49 ## mat2str ([ -1/3 +i/7; 1/3 -i/7 ], [4 2])
13314
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
50 ## @result{} "[-0.3333+0i 0+0.14i;0.3333+0i -0-0.14i]"
8442
502e58a0d44f Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7812
diff changeset
51 ##
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
52 ## mat2str (int16 ([1 -1]), "class")
13314
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
53 ## @result{} "int16([1 -1])"
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
54 ##
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
55 ## mat2str (logical (eye (2)))
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
56 ## @result{} "[true false;false true]"
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
57 ##
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
58 ## isequal (x, eval (mat2str (x)))
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
59 ## @result{} 1
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
60 ## @end group
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
61 ## @end example
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
62 ##
8442
502e58a0d44f Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7812
diff changeset
63 ## @seealso{sprintf, num2str, int2str}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
64 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
65
13314
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
66 function s = mat2str (x, n = 15, cls = "")
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
67
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27978
diff changeset
68 if (nargin < 1 || ! (isnumeric (x) || islogical (x)))
13180
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
69 print_usage ();
13314
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
70 elseif (ndims (x) > 2)
13180
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
71 error ("mat2str: X must be two dimensional");
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
72 endif
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
73
13314
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
74 if (nargin == 2 && ischar (n))
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
75 cls = n;
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
76 n = 15;
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
77 elseif (isempty (n))
13180
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
78 n = 15; # Default precision
19725
5f2c0ca0ef51 Ensure that numbers passed to integer *printf format codes are integers (bug #44245).
Rik <rik@octave.org>
parents: 19697
diff changeset
79 elseif (numel (n) > 2)
5f2c0ca0ef51 Ensure that numbers passed to integer *printf format codes are integers (bug #44245).
Rik <rik@octave.org>
parents: 19697
diff changeset
80 error ("mat2str: N must have only 1 or 2 elements");
5f2c0ca0ef51 Ensure that numbers passed to integer *printf format codes are integers (bug #44245).
Rik <rik@octave.org>
parents: 19697
diff changeset
81 else
5f2c0ca0ef51 Ensure that numbers passed to integer *printf format codes are integers (bug #44245).
Rik <rik@octave.org>
parents: 19697
diff changeset
82 n = fix (n);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
83 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
84
11485
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
85 x_islogical = islogical (x);
7812
c25094267486 strings/mat2str.m: Change is_complex to iscomplex, add tests, add missing ;
kimhanse@gmail.com
parents: 7017
diff changeset
86 x_iscomplex = iscomplex (x);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
87
11485
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
88 if (x_iscomplex)
13314
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
89 if (isscalar (n))
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
90 n = [n, n];
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
91 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
92 fmt = sprintf ("%%.%dg%%+.%dgi", n(1), n(2));
11485
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
93 elseif (x_islogical)
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
94 v = {"false", "true"};
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
95 fmt = "%s";
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
96 else
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
97 fmt = sprintf ("%%.%dg", n(1));
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
98 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
99
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
100 nel = numel (x);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
101
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
102 if (nel == 0)
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
103 ## Empty, only print brackets
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
104 s = "[]";
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
105 elseif (nel == 1)
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
106 ## Scalar X, don't print brackets
11485
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
107 if (x_iscomplex)
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
108 s = sprintf (fmt, real (x), imag (x));
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
109 elseif (x_islogical)
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
110 s = v{x+1};
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
111 else
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
112 s = sprintf (fmt, x);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
113 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
114 else
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
115 ## Non-scalar X, print brackets
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
116 fmt = [fmt " "];
11485
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
117 if (x_iscomplex)
7812
c25094267486 strings/mat2str.m: Change is_complex to iscomplex, add tests, add missing ;
kimhanse@gmail.com
parents: 7017
diff changeset
118 t = x.';
c25094267486 strings/mat2str.m: Change is_complex to iscomplex, add tests, add missing ;
kimhanse@gmail.com
parents: 7017
diff changeset
119 s = sprintf (fmt, [real(t(:))'; imag(t(:))']);
11485
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
120 elseif (x_islogical)
27680
f998e243fa78 mat2str.m: Fix for logical matrix (add transpose)
Andreas Weber <octave@josoansi.de>
parents: 26376
diff changeset
121 t = v(x.'+1);
11485
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
122 s = cstrcat (sprintf (fmt, t{:}));
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
123 else
571bfa4fc295 mat2str: handle logical arguments
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
124 s = sprintf (fmt, x.');
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
125 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
126
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
127 s = ["[" s];
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
128 s(end) = "]";
13314
da56d27164fe mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents: 13180
diff changeset
129 idx = strfind (s, " ");
5946
4b433225128d [project @ 2006-08-21 15:54:50 by jwe]
jwe
parents: 5838
diff changeset
130 nc = columns (x);
13180
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
131 s(idx(nc:nc:end)) = ";";
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
132 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
133
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
134 if (strcmp ("class", cls))
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
135 s = [class(x) "(" s ")"];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
136 endif
13180
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
137
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
138 endfunction
7812
c25094267486 strings/mat2str.m: Change is_complex to iscomplex, add tests, add missing ;
kimhanse@gmail.com
parents: 7017
diff changeset
139
13180
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
140
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
141 %!assert (mat2str (0.7), "0.7")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
142 %!assert (mat2str (pi), "3.14159265358979")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
143 %!assert (mat2str (pi, 5), "3.1416")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
144 %!assert (mat2str (single (pi), 5, "class"), "single(3.1416)")
30330
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
145 %!assert (mat2str ([-1/3 + i/7; 1/3 - i/7], [4 2]),
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
146 %! "[-0.3333+0.14i;0.3333-0.14i]")
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
147 %!assert (mat2str ([-1/3 +i/7; 1/3 -i/7], [4 2]),
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
148 %! "[-0.3333+0i 0+0.14i;0.3333+0i -0-0.14i]")
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
149 %!assert (mat2str (int16 ([1 -1]), "class"), "int16([1 -1])")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
150 %!assert (mat2str (true), "true")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
151 %!assert (mat2str (false), "false")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
152 %!assert (mat2str (logical (eye (2))), "[true false;false true]")
27680
f998e243fa78 mat2str.m: Fix for logical matrix (add transpose)
Andreas Weber <octave@josoansi.de>
parents: 26376
diff changeset
153 %!assert (mat2str (logical ([0 1; 0 0])), "[false true;false false]")
13180
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
154
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19725
diff changeset
155 ## Test input validation
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
156 %!error <Invalid call> mat2str ()
13180
c215352ddb4f mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents: 12611
diff changeset
157 %!error mat2str (["Hello"])
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
158 %!error <X must be two dimensional> mat2str (ones (3,3,2))
19725
5f2c0ca0ef51 Ensure that numbers passed to integer *printf format codes are integers (bug #44245).
Rik <rik@octave.org>
parents: 19697
diff changeset
159 %!error <N must have only 1 or 2 elements> mat2str (ones (3,3), [1 2 3])