Mercurial > octave
annotate scripts/strings/mat2str.m @ 28886:d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Remove BIST tests now that interpreter enforces calling function with no more than
the number of arguments defined in the function prototype.
* makeUniqueStrings.m, makeValidName.m, base64decode.m, base64encode.m,
record.m, sound.m, soundsc.m, acosd.m, acot.m, acotd.m, acoth.m, acsc.m,
acscd.m, acsch.m, asec.m, asecd.m, asech.m, asind.m, atan2d.m, atand.m, cosd.m,
cot.m, cotd.m, coth.m, csc.m, cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m,
tand.m, accumdim.m, bincoeff.m, bitget.m, bitset.m, cell2mat.m, circshift.m,
cplxpair.m, cumtrapz.m, deg2rad.m, flip.m, fliplr.m, flipud.m, int2str.m,
interpft.m, logspace.m, num2str.m, postpad.m, prepad.m, rad2deg.m, rot90.m,
rotdim.m, shift.m, subsindex.m, trapz.m, rotx.m, roty.m, rotz.m, getappdata.m,
getpixelposition.m, guidata.m, isappdata.m, waitforbuttonpress.m,
__gripe_missing_component__.m, bessel.m, hsv2rgb.m, ind2gray.m, rgb2gray.m,
rgb2hsv.m, rgbplot.m, fileread.m, javachk.m, usejava.m, findstr.m,
genvarname.m, isdir.m, vectorize.m, cond.m, cross.m, duplication_matrix.m,
expm.m, isbanded.m, isdefinite.m, isdiag.m, ishermitian.m, issymmetric.m,
istril.m, istriu.m, trace.m, vech.m, vecnorm.m, cast.m, citation.m,
compare_versions.m, grabcode.m, inputname.m, isfile.m, isfolder.m, ismac.m,
ispc.m, isunix.m, list_primes.m, methods.m, news.m, open.m, run.m, swapbytes.m,
tar.m, verLessThan.m, zip.m, odeget.m, optimget.m, stemleaf.m, allchild.m,
ancestor.m, close.m, groot.m, hgsave.m, isaxes.m, isfigure.m, isgraphics.m,
ishandle.m, isprop.m, linkaxes.m, rotate.m, saveas.m, conv.m, poly.m,
polyint.m, polyreduce.m, ppval.m, roots.m, addpref.m, getpref.m, ispref.m,
rmpref.m, setpref.m, profile.m, profshow.m, powerset.m, autoreg_matrix.m,
bartlett.m, blackman.m, detrend.m, fftconv.m, fftfilt.m, fftshift.m, hamming.m,
hanning.m, ifftshift.m, sinewave.m, spectral_adf.m, spectral_xdf.m, unwrap.m,
nonzeros.m, spconvert.m, sprand.m, sprandn.m, beta.m, betainc.m, betaln.m,
cosint.m, expint.m, factorial.m, legendre.m, nchoosek.m, nthroot.m, perms.m,
pow2.m, primes.m, reallog.m, realpow.m, realsqrt.m, sinint.m, hankel.m, hilb.m,
invhilb.m, magic.m, pascal.m, toeplitz.m, vander.m, wilkinson.m, center.m,
corr.m, cov.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, empirical_cdf.m,
empirical_inv.m, empirical_pdf.m, iqr.m, kendall.m, kurtosis.m, mad.m,
meansq.m, median.m, moment.m, prctile.m, quantile.m, range.m, run_count.m,
skewness.m, spearman.m, statistics.m, std.m, var.m, base2dec.m, bin2dec.m,
blanks.m, dec2base.m, dec2bin.m, dec2hex.m, endsWith.m, erase.m, hex2dec.m,
index.m, isletter.m, isstring.m, isstrprop.m, mat2str.m, ostrsplit.m, rindex.m,
startsWith.m, strtrunc.m, substr.m, fail.m, addtodate.m, asctime.m, ctime.m,
date.m, datestr.m, eomday.m, etime.m, is_leap_year.m, now.m:
remove unnecessary BIST tests in m-files checking for excessive number of inputs.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 09 Oct 2020 13:28:53 -0700 |
parents | 28de41192f3c |
children | 7854d5752dd2 |
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 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2002-2020 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 | 7 ## |
8 ## This file is part of Octave. | |
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 | 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 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
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 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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 | 25 |
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 | 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 | 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 | 42 ## construction of a matrix of the same class. |
43 ## | |
44 ## @example | |
45 ## @group | |
8507 | 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 | 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 | 60 ## @end group |
61 ## @end example | |
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 | 64 ## @end deftypefn |
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 | 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 | 83 endif |
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 | 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 | 90 n = [n, n]; |
91 endif | |
5838 | 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 | 98 endif |
99 | |
5838 | 100 nel = numel (x); |
5837 | 101 |
5838 | 102 if (nel == 0) |
103 ## Empty, only print brackets | |
5837 | 104 s = "[]"; |
5838 | 105 elseif (nel == 1) |
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 | 112 s = sprintf (fmt, x); |
5837 | 113 endif |
5838 | 114 else |
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 | 125 endif |
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 | 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 | 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 | 132 endif |
133 | |
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 | 136 endif |
13180
c215352ddb4f
mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents:
12611
diff
changeset
|
137 |
5837 | 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)") |
7812
c25094267486
strings/mat2str.m: Change is_complex to iscomplex, add tests, add missing ;
kimhanse@gmail.com
parents:
7017
diff
changeset
|
145 %!assert (mat2str ([-1/3 + i/7; 1/3 - i/7], [4 2]), "[-0.3333+0.14i;0.3333-0.14i]") |
13314
da56d27164fe
mat2str.m: Tune function for Matlab compatability and speed.
Rik <octave@nomad.inbox5.com>
parents:
13180
diff
changeset
|
146 %!assert (mat2str ([-1/3 +i/7; 1/3 -i/7], [4 2]), "[-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
|
147 %!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
|
148 %!assert (mat2str (true), "true") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
149 %!assert (mat2str (false), "false") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
150 %!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
|
151 %!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
|
152 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19725
diff
changeset
|
153 ## 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
|
154 %!error <Invalid call> mat2str () |
13180
c215352ddb4f
mat2str.m: Use more modern code syntax for function
Rik <octave@nomad.inbox5.com>
parents:
12611
diff
changeset
|
155 %!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
|
156 %!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
|
157 %!error <N must have only 1 or 2 elements> mat2str (ones (3,3), [1 2 3]) |