asciimat() proposed page (PDF): http://bugzilla.scilab.org/attachment.cgi?id=5266
http://bugzilla.scilab.org/16438 :
Support to strings of distinct lengths added.
Support to strings including UTF8 extended characters added.
http://bugzilla.scilab.org/16685 :
asciimat(['ab';'';'ab']) result was wrongly shaped.
asciimat(['a';'';'b']) yielded an error.
asciimat(stringHypermat) squeezed dim#2 of the result and so
did not cope with Matlab/Octave's behavior.
test_run string asciimat
test_run string bug_14976
test_run statistics histc
To keep track of its files changes, asciimat() will be moved in [m2sci] only later.
In addition, an option could be implemented later, to make asciimat(text)
fully working in an elementwise way (as first proposed @
https://codereview.scilab.org/21566 )
Change-Id: I3183fc3d05491066816034802e8f09645261d76e
* `hash` function with SHA-1,SHA-2 and SHA-3 Secure Hash Algorithms has been added.
* `loglog`, `semilogx`, `semilogy` Matlab-compatible functions added.
* `scatter` and `scatter3d` are reforged. New `scatter` options: `"smallOnTop"` and `"datatips"`.
+* `asciimat` now supports input strings of different lengths or including international UTF8 extended characters.
Help pages:
* [#16406](https://bugzilla.scilab.org/16406): `edit_curv` yielded an error when reading data.
* [#16407](https://bugzilla.scilab.org/16407): Fec rendering was incorrect
* [#16408](https://bugzilla.scilab.org/16408): toJSON(var, indent, filename) is the right call sequence. Documentation has been udpated.
+* [#16438](https://bugzilla.scilab.org/16438): `asciimat(text)` did not accept strings of different lengths or including some extended UTF-8 characters.
* [#16445](https://bugzilla.scilab.org/16445): `colorbar(..)` ignored how to guess `umin` and `umax` for a Champ object (with .colored="on").
* [#16449](https://bugzilla.scilab.org/16449): Insertion of implicit vector in Cell was crahsing Scilab
* [#16450](https://bugzilla.scilab.org/16450): Concatenating encoded integers with decimal or complex numbers was not possible.
* [#16677](https://bugzilla.scilab.org/16677): In offline mode, `atomsInstall` was flashing many times the console.
* [#16679](https://bugzilla.scilab.org/16679): `get_function_path("acosh")` yielded an error (regression from Scilab 6.0.0).
* [#16683](https://bugzilla.scilab.org/16683): The `m2sci` code converter needed a set of fix and improvements.
+* [#16685](https://bugzilla.scilab.org/16685): `asciimat("A";"";"B")` yielded a transposed matrix of codes. When processing an hypermatrix of codes, the dim#2 of the result was squeezed (unlike Matlab/Octave's behavior).
### Bugs fixed in 6.1.0:
// Gathering locals + globals
%_nams_all = [%_nams ; %_nams_global];
%_vol_all = [%_vol ; %_vol_global];
- %_LG_all = [asciimat(76*ones(%_vol(:))) ; asciimat(71*ones(%_vol_global(:)))];
+ %_LG_all = [emptystr(%_vol(:))+"L" ; emptystr(%_vol_global(:))+"G"];
// Sorting the whole set w/o.r.t. the case
[trash, k] = gsort(convstr(%_nams_all,"l"),"g","i");
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
-//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2021 - Samuel GOUGEON
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// For more information, see the COPYING file which you should have received
// along with this program.
-function r=%c_b_c(varargin)
+function r = %c_b_c(varargin)
if size(varargin)==2 then
if type(varargin(1))==10 & type(varargin(2))==10 then
- r = asciimat(asciimat(varargin(1)):asciimat(varargin(2)))
- end
- elseif size(varargin)==3 then
- if type(varargin(1))==10 & type(varargin(2))==10 & type(varargin(3))==10 then
- r = asciimat(asciimat(varargin(1)):asciimat(varargin(2)):asciimat(varargin(3)))
+ s = ascii(varargin(1))
+ e = ascii(varargin(2))
+ if s>e, step = -1, else step = 1, end
+ r = ascii(s:step:e)
end
else
msg = _("%s: Non implemented feature.\n");
error(msprintf(msg, "char:char"));
end
endfunction
+//assert_checkequal("a":"z", "abcdefghijklmnopqrstuvwxyz");
+//assert_checkequal("z":"a", "zyxwvutsrqponmlkjihgfedcba");
+
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
-//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2021 - Samuel GOUGEON
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// along with this program.
function r = %c_b_s(varargin)
- if size(varargin)==3 then
- if type(varargin(1))==10 & type(varargin(2))==1 & type(varargin(3))==10 then
- r=asciimat(asciimat(varargin(1)):varargin(2):asciimat(varargin(3)))
- end
+ if size(varargin)==3 & type(varargin(3))==10 & ..
+ length(ascii(varargin(1)))==1 & length(ascii(varargin(3)))==1
+ r = ascii(ascii(varargin(1)):varargin(2):ascii(varargin(3)))
else
msg = _("%s: Non implemented feature.\n");
error(msprintf(msg, "char:num"));
end
endfunction
+//assert_checkequal("a":2:"z", "acegikmoqsuwy");
+//assert_checkequal("z":-1:"a", "zyxwvutsrqponmlkjihgfedcba");
+//assert_checkequal("z":-2:"a", "zxvtrpnljhfdb");
+//assert_checkequal("a":-1:"z", "");
+//assert_checkequal("z":2:"a", "");
assert_checkequal(size(b),[1,5]);
assert_checkequal(size(i),[2,9]);
// Texts
-t = matrix(asciimat(grand(20,1,"uin",ascii("a"), ascii("z"))), 2, 10);
+t = grand(20,1,"uin",ascii("a"), ascii("z"));
+t = matrix(strsplit(ascii(t)), 2, 10);
[h,j,b,i] = histc(t, ["e" "i" "o" "u"]);
assert_checkequal(size(h),[1,3]);
assert_checkequal(size(j),[1,3]);
[h,j,b,i] = histc(t);
assert_checkequal(h, [3 3 2 3 1 5 1 7 6 4 2 4 2 4 8 5]);
assert_checkequal(j, [0 0 0]);
-assert_checkequal(b, asciimat((97:112)')');
+assert_checkequal(b, strsplit("a":"p")');
iref = [
3 14 8 9 2 9 6 9 16 12 16 4 6 9 12
2 13 5 15 15 6 16 15 8 6 8 8 3 11 15
assert_checkequal(h, href/N);
assert_checkequal(j, jref/N);
[h,j,b,i] = histc(t2, [bref ""], "discrete,countsNorm,normWith: empty");
+
assert_checkequal(h, href/N);
assert_checkequal(j, jref/N);
[h,j,b,i] = histc(t2, [bref ""], "discrete,countsNorm,normWith: out");
<?xml version="1.0" encoding="UTF-8"?>
<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT
- *
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT
* Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2020 - 2021 - Samuel GOUGEON
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* and continues to be available under such terms.
* For more information, see the COPYING file which you should have received
* along with this program.
- *
- -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="asciimat">
+ *
+-->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg" xmlns:db="http://docbook.org/ns/docbook"
+ xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="asciimat">
<refnamediv>
<refname>asciimat</refname>
- <refpurpose>string matrix ASCII conversions</refpurpose>
+ <refpurpose>
+ Converts an array of text into ASCII/UTF8 codes, and reciprocally
+ </refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Syntax</title>
<synopsis>
- a = asciimat(txt)
- txt = asciimat(a)
+ unicodes = asciimat(text)
+ text = asciimat(unicodes)
</synopsis>
</refsynopsisdiv>
<refsection>
<title>Arguments</title>
<variablelist>
<varlistentry>
- <term>txt</term>
+ <term>text</term>
<listitem>
- <para>
- a character string or matrix of strings.
- </para>
+ single text, or vector, matrix or hypermatrix of texts.
+ Text elements may have various lengths, and may include UTF-8 extended characters.
+ <para/>
+ <literal>asciimat(…)</literal> always concatenates the columns of
+ <varname>text</varname> along rows, as input or output argument.
+ <para/>
</listitem>
</varlistentry>
<varlistentry>
- <term>a</term>
+ <term>unicodes</term>
<listitem>
- <para>
- a vector or matrix of integer ASCII codes.
- </para>
+ single integer ASCII code, or vector, matrix or hypermatrix of ASCII or unicode
+ 1-byte numbers.
+ <para/>
</listitem>
</varlistentry>
</variablelist>
<refsection>
<title>Description</title>
<para>
- This function converts Scilab string to ASCII code or a
- matrix of ASCII code to Scilab string. Output is a matrix
- having the same number of rows than input, what is not the
- case with <function>ascii</function>.
+ <literal>asciimat(…)</literal> converts an array of <varname>text</varname>
+ into an array of related 1-byte ascii or UTF-8 <varname>unicodes</varname>,
+ and reciprocally.
+ </para>
+ <para>
+ <literal>asciimat(…)</literal> is an Octave/Matlab compatibility function,
+ aiming to provide in the m2sci
+ Matlab-to-Scilab code converter an equivalence for the addition and
+ subtraction between some character strings or with numbers. Thus,
+ <screen><![CDATA[
+>> ['ab' 'c' ; 'd' 'ef'] + 4
+ans =
+ 101 102 103
+ 104 105 106
+
+>> ['ab';'cd'] + ['ef';'gh']
+ans =
+ 198 200
+ 202 204
+
+>> ['ab';'cd'] - ['ef';'gh']
+ans =
+ -4 -4
+ -4 -4
+]]></screen>
+ </para>
+ <para>
+ can be performed by the Matlab-to-Scilab converter with
+ </para>
+ <para>
+ <programlisting role="example"><![CDATA[
+asciimat(['ab' 'c' ; 'd' 'ef']) + 4
+asciimat(['ab';'cd']) + asciimat(['ef';'gh'])
+asciimat(['ab';'cd']) - asciimat(['ef';'gh'])
+ ]]></programlisting>
+ </para>
+ <para>
+ <warning>
+ <literal>asciimat(…)</literal> should not be used out of the M2Sci converter.
+ </warning>
+ </para>
+ <refsect3>
+ <title>unicodes = asciimat(text)</title>
+ <para>
+ <emphasis role="bold">For a scalar or row</emphasis> <varname>text</varname>,
+ <literal>asciimat(text)</literal> is equal to <literal>ascii(text)</literal>.
+ All strings are glued together before building the row vector of codes of their
+ characters.
+ </para>
+ <para>
+ <warning>
+ <emphasis role="bold">For any <varname>text</varname> array of any sizes,
+ made only of empty strings ""</emphasis>, <literal>asciimat(text)</literal>
+ returns []. Indeed, <literal>asciimat(…)</literal> considers "" as a void vector
+ of (indexed) characters as in Octave/Matlab, not as a Scilab text object.
+ </warning>
+ </para>
+ <para>
+ <emphasis role="bold">For a 2D matrix</emphasis> <varname>text</varname>,
+ <literal>asciimat(text)</literal> builds a unique column of text by gluing
+ <varname>text</varname> columns along rows.
+ </para>
+ <para>
+ Then, for each row/string of the column, the row vector of ASCII or
+ UTF-8 codes of all its characters is computed.
+ </para>
+ <para>
+ Finally, all resulting row vectors of codes are vertically concatenated to
+ build the <varname>unicodes</varname> matrix. Too short vectors of codes
+ are beforehand padded with the ascii(" ")==32 code.
+ </para>
+ <para>
+ <emphasis role="bold">For an hypermatrix</emphasis> of <varname>text</varname>,
+ the processing is basically the same, as if all <varname>text</varname>
+ rows over all dimensions > 2 were beforehand stacked into a 2D matrix.
+ The resulting 2D <varname>unicodes</varname> matrix is finally reshaped into
+ an hypermatrix..
+ </para>
+ <para>
+ The sizes of <varname>unicodes</varname> and <varname>text</varname> arrays
+ differ only by their number of columns.
+ </para>
+ </refsect3>
+ <refsect3>
+ <title>text = asciimat(unicodes)</title>
+ <para>
+ <emphasis role="bold">For a scalar or a row </emphasis> <varname>unicodes</varname>,
+ <literal>asciimat(unicodes)</literal> is equal to <literal>ascii(unicodes)</literal>.
+ It returns the character string whose characters have the given codes.
+ <warning>
+ Zeros stand for the code of the empty character "", as the true
+ ascii(0) character is currently not supported in Scilab 6.
+ </warning>
+ </para>
+ <para>
+ <emphasis role="bold">For a column, matrix or hypermatrix</emphasis>
+ <varname>unicodes</varname>, each <varname>unicodes</varname> row is
+ processed separately and builds a single Scilab character string.
+ </para>
+ <para>
+ All trailing ascii(32) spaces of built character strings are trimmed.
+ </para>
+ <para>
+ Finally, <varname>text</varname> has the size of <varname>unicodes</varname>,
+ except that <literal>size(text,2)==1</literal>.
+ </para>
+ </refsect3>
+ </refsection>
+ <refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+asciimat([])
+asciimat("")
+asciimat(0)
+
+r = asciimat("A")
+asciimat(r)
+
+// With an input ROW:
+r = asciimat(["A" "BC"])
+asciimat(r)
+
+r = asciimat(["A" "" "BC"]) // "" in rows are ignored
+asciimat(r)
+ ]]></programlisting>
+ <screen><![CDATA[
+--> asciimat([])
+ ans =
+ []
+--> asciimat("")
+ ans =
+ []
+--> asciimat(0)
+ ans =
+ ""
+
+--> r = asciimat("A")
+ r =
+ 65.
+--> asciimat(r)
+ ans =
+ "A"
+
+--> // With an input ROW:
+--> r = asciimat(["A" "BC"])
+ r =
+ 65. 66. 67.
+
+--> asciimat(r)
+ ans =
+ "ABC"
+
+--> r = asciimat(["A" "" "BC"]) // "" in rows are ignored
+ r =
+ 65. 66. 67.
+
+--> asciimat(r)
+ ans =
+ "ABC"
+]]></screen>
+ <para>
+ With an input column:
+ </para>
+ <programlisting role="example"><![CDATA[
+asciimat(["" ; ""])
+asciimat((97:110)')'
+strsplit("a":"n")'
+
+r = asciimat(["ABC" ; "" ; "D"]) // Padding short rows with 32
+asciimat(r)
+r = asciimat(["AB" ; "αβ"]) // 1-byte UTF-8 coding is used
+asciimat(r) // Trailing ascii(32) spaces are trimmed
+ ]]></programlisting>
+ <screen><![CDATA[
+--> asciimat(["" ; ""])
+ ans =
+ []
+
+--> asciimat((97:110)')'
+ ans =
+ "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
+
+--> strsplit("a":"n")'
+ ans =
+ "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
+
+--> r = asciimat(["ABC" ; "" ; "D"]) // Padding short rows with 32
+ r =
+ 65. 66. 67.
+ 32. 32. 32.
+ 68. 32. 32.
+
+--> asciimat(r)
+ ans =
+ "ABC"
+ ""
+ "D"
+
+--> r = asciimat(["AB" ; "αβ"]) // 1-byte UTF-8 coding is used
+ r =
+ 65. 66. 32. 32.
+ 206. 177. 206. 178.
+
+--> asciimat(r) // Trailing ascii(32) spaces are trimmed
+ ans =
+ "AB"
+ "αβ"
+]]></screen>
+ <para>
+ With a 2D input matrix:
</para>
+ <programlisting role="example"><![CDATA[
+r = asciimat([" AB", " ", "CD " ; "α", "βγ", " "])
+asciimat(r)
+ ]]></programlisting>
+ <screen><![CDATA[
+--> r = asciimat([" AB", " ", "CD " ; "α", "βγ", " "])
+ r =
+ 32. 65. 66. 32. 67. 68. 32.
+ 206. 177. 206. 178. 206. 179. 32.
+
+--> asciimat(r)
+ ans =
+ " AB CD"
+ "αβγ"
+]]></screen>
+ <para>
+ With a 3D input hypermatrix:
+ </para>
+ <programlisting role="example"><![CDATA[
+x = ["a €" "bδ " ; "" "" ; "" "" ];
+x2 = [" α" "βδc" ; "" "" ; "ε4" ""];
+h = cat(3, x, x2)
+r = asciimat(h)
+asciimat(r)
+ ]]></programlisting>
+ <screen><![CDATA[
+--> h = cat(3, x, x2)
+ h =
+(:,:,1)
+ "a €" "bδ "
+ "" ""
+ "" ""
+(:,:,2)
+ " α" "βδc"
+ "" ""
+ "ε4" ""
+
+--> r = asciimat(h)
+ r =
+(:,:,1)
+ 97. 32. 226. 130. 172. 98. 206. 180. 32.
+ 32. 32. 32. 32. 32. 32. 32. 32. 32.
+ 32. 32. 32. 32. 32. 32. 32. 32. 32.
+(:,:,2)
+ 32. 206. 177. 206. 178. 206. 180. 99. 32.
+ 32. 32. 32. 32. 32. 32. 32. 32. 32.
+ 206. 181. 52. 32. 32. 32. 32. 32. 32.
+
+--> asciimat(r)
+ ans =
+(:,:,1)
+ "a €bδ"
+ ""
+ ""
+(:,:,2)
+ " αβδc"
+ ""
+ "ε4"
+]]></screen>
</refsection>
+
<refsection role="see also">
<title>See also</title>
<simplelist type="inline">
<member>
<link linkend="ascii">ascii</link>
</member>
+ <member>
+ <link linkend="char">char</link>
+ </member>
</simplelist>
</refsection>
+
+ <refsection role="history">
+ <title>History</title>
+ <revhistory>
+ <revision>
+ <revnumber>6.1.1</revnumber>
+ <revdescription>
+ <itemizedlist>
+ <listitem>
+ Text components with various lengths or/and including UTF-8 characters
+ are accepted. Padding with the ascii(" ")==32 code implemented.
+ </listitem>
+ <listitem>
+ asciimat(unicodes) trims all trailing spaces.
+ </listitem>
+ <listitem>
+ For any unicodes hypermatrix, r = asciimat(unicodes) no longer squeezes
+ size(r,2).
+ </listitem>
+ </itemizedlist>
+ </revdescription>
+ </revision>
+ </revhistory>
+ </refsection>
</refentry>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2002-2004 - INRIA - Vincent COUVERT
- *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * This file is hereby licensed under the terms of the GNU GPL v2.0,
- * pursuant to article 5.3.4 of the CeCILL v.2.1.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * along with this program.
- *
- -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="fr" xml:id="asciimat">
- <refnamediv>
- <refname>asciimat</refname>
- <refpurpose>conversion d'une matrice de chaînes ASCII</refpurpose>
- </refnamediv>
- <refsynopsisdiv>
- <title>Séquence d'appel</title>
- <synopsis>
- a = asciimat(txt)
- txt = asciimat(a)
- </synopsis>
- </refsynopsisdiv>
- <refsection>
- <title>Paramètres</title>
- <variablelist>
- <varlistentry>
- <term>txt</term>
- <listitem>
- <para>chaîne de caractères ou matrice de chaînes</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>a</term>
- <listitem>
- <para>vecteur ou matrice de codes ASCII</para>
- </listitem>
- </varlistentry>
- </variablelist>
- </refsection>
- <refsection>
- <title>Description</title>
- <para>
- Cette fonction convertit une chaîne de caractères Scilab en codes ASCII ou une matrice de codes ASCII en chaîne de caractères Scilab.
- La valeur retournée est une matrice ayant le même nombre de lignes que l'entrée,
- ce qui n'est pas le cas de la fonction <function>ascii</function>.
- </para>
- </refsection>
- <refsection role="see also">
- <title>Voir aussi</title>
- <simplelist type="inline">
- <member>
- <link linkend="ascii">ascii</link>
- </member>
- </simplelist>
- </refsection>
-</refentry>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT
- *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * This file is hereby licensed under the terms of the GNU GPL v2.0,
- * pursuant to article 5.3.4 of the CeCILL v.2.1.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * along with this program.
- *
- -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ja" xml:id="asciimat">
- <refnamediv>
- <refname>asciimat</refname>
- <refpurpose>文字列行列アスキー変換</refpurpose>
- </refnamediv>
- <refsynopsisdiv>
- <title>呼び出し手順</title>
- <synopsis>
- a = asciimat(txt)
- txt = asciimat(a)
- </synopsis>
- </refsynopsisdiv>
- <refsection>
- <title>引数</title>
- <variablelist>
- <varlistentry>
- <term>txt</term>
- <listitem>
- <para>
- 文字列または文字列の行列.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term>a</term>
- <listitem>
- <para>
- 整数アスキーコードのベクトルまたは行列.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </refsection>
- <refsection>
- <title>説明</title>
- <para>
- この関数は,Scilab文字列をアスキーコードに変換または
- アスキーコードの行列をScilab文字列に変換します.
- 出力は,<function>ascii</function>の場合と異なり,
- 入力と同じ行数を有する行列です.
- </para>
- </refsection>
- <refsection role="see also">
- <title>参照</title>
- <simplelist type="inline">
- <member>
- <link linkend="ascii">ascii</link>
- </member>
- </simplelist>
- </refsection>
-</refentry>
<?xml version="1.0" encoding="UTF-8"?>
<!--
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT
- *
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT
* Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2020 - 2021 - Samuel GOUGEON
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* and continues to be available under such terms.
* For more information, see the COPYING file which you should have received
* along with this program.
- *
- -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ru" xml:id="asciimat">
+ *
+-->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg" xmlns:db="http://docbook.org/ns/docbook"
+ xmlns:scilab="http://www.scilab.org" xml:lang="ru" xml:id="asciimat">
<refnamediv>
<refname>asciimat</refname>
- <refpurpose>преобразование матрицы строк в ASCII-коды и обратно</refpurpose>
+ <refpurpose>
+ Преобразует массив текста в коды ASCII/UTF8 и обратно
+ </refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Синтаксис</title>
<synopsis>
- a = asciimat(txt)
- txt = asciimat(a)
+ unicodes = asciimat(text)
+ text = asciimat(unicodes)
</synopsis>
</refsynopsisdiv>
<refsection>
<title>Аргументы</title>
<variablelist>
<varlistentry>
- <term>txt</term>
+ <term>text</term>
<listitem>
- <para>
- символьная строка или матрица строк.
- </para>
+ отдельный текст, или вектор, матрица или гиперматрица текстов.
+ Элементы текста могут иметь разную длину и могут включать в
+ себя расширенные символы UTF-8.
+ <para/>
+ <literal>asciimat(…)</literal> всегда конкатенирует столбцы текста
+ <varname>text</varname> вдоль строк, как входной или выходной аргумент.
+ <para/>
</listitem>
</varlistentry>
<varlistentry>
- <term>a</term>
+ <term>unicodes</term>
<listitem>
- <para>
- вектор или матрица целочисленных ASCII-кодов.
- </para>
+ отдельный целочисленный ASCII-код, вектор, матрица или гиперматрица
+ 1-байтных чисел ASCII или юникода.
+ <para/>
</listitem>
</varlistentry>
</variablelist>
<refsection>
<title>Описание</title>
<para>
- Эта функция преобразует Scilab-строку в ASCII-код или
- матрицу ASCII-кодов в Scilab-строку. Аргумент на выходе
- является матрицей, у которой то же количество строк, что и у
- матрицы на входе, что является отличием от функции
- <function>ascii</function>.
+ <literal>asciimat(…)</literal> преобразует массив текста <varname>text</varname>
+ в массив соответствующих 1-байтных кодов ascii или UTF-8 <varname>unicodes</varname>,
+ и наоборот.
+ </para>
+ <para>
+ <literal>asciimat(…)</literal> является функцией совместимости с Octave/Matlab,
+ с целью обеспечить в преобразователе кода Matlab-в-Scilab m2sci
+ эквивалентность для суммирования и вычитания некоторых
+ строковых символов или с числами. Таким образом,
+ <screen><![CDATA[
+>> ['ab' 'c' ; 'd' 'ef'] + 4
+ans =
+ 101 102 103
+ 104 105 106
+
+>> ['ab';'cd'] + ['ef';'gh']
+ans =
+ 198 200
+ 202 204
+
+>> ['ab';'cd'] - ['ef';'gh']
+ans =
+ -4 -4
+ -4 -4
+]]></screen>
+ </para>
+ <para>
+ может быть преобразовано преобразователем Matlab-в-Scilab с
+ </para>
+ <para>
+ <programlisting role="example"><![CDATA[
+asciimat(['ab' 'c' ; 'd' 'ef']) + 4
+asciimat(['ab';'cd']) + asciimat(['ef';'gh'])
+asciimat(['ab';'cd']) - asciimat(['ef';'gh'])
+ ]]></programlisting>
+ </para>
+ <para>
+ <warning>
+ <literal>asciimat(…)</literal> не следует использовать без преобразователя.
+ </warning>
+ </para>
+ <refsect3>
+ <title>unicodes = asciimat(text)</title>
+ <para>
+ <emphasis role="bold">Для скаляра или строки</emphasis> <varname>text</varname>,
+ <literal>asciimat(text)</literal> эквивалентно <literal>ascii(text)</literal>.
+ Все строчки склеиваются друг с другом перед построением вектора-строки
+ кодов их символов.
+ </para>
+ <para>
+ <warning>
+ <emphasis role="bold">Для любого массива <varname>text</varname> любых
+ размеров, сделанных только из пустых строк <literal>""</literal></emphasis>,
+ <literal>asciimat(text)</literal> возвращает <literal>[]</literal>.
+ Действительно, <literal>asciimat(…)</literal> считает <literal>""</literal>
+ как пустой вектор (индексированных) символов как в Octave/Matlab, а не
+ как текстовый объект Scilab.
+ </warning>
+ </para>
+ <para>
+ <emphasis role="bold">Для двумерных матриц</emphasis> <varname>text</varname>,
+ <literal>asciimat(text)</literal> строит уникальный столбец текста,
+ склеивая столбцы <varname>text</varname> вдоль строк.
+ </para>
+ <para>
+ Затем для каждой строки/строчки столбца вычисляется вектор-строка
+ кодов ASCII или UTF-8 всех её символов.
+ </para>
+ <para>
+ Наконец, все результирующие вектор-строки кодов конкатенируются
+ по вертикали для построения матрицы <varname>unicodes</varname>.
+ Слишком короткие векторы кодов предварительно дополняются кодом
+ ascii(" ")==32.
+ </para>
+ <para>
+ <emphasis role="bold">Для гиперматрицы</emphasis> <varname>text</varname>,
+ обработка, в основном, та же самая, как если бы все строки
+ <varname>text</varname> по всем размерностям больше двух были предварительно
+ составлены в двумерную матрицу. Результирующая двумерная матрица
+ <varname>unicodes</varname>, наконец, преобразуется в гиперматрицу.
+ </para>
+ <para>
+ Размеры массивов <varname>unicodes</varname> и <varname>text</varname>
+ отличаются только по количеству их столбцов.
+ </para>
+ </refsect3>
+ <refsect3>
+ <title>text = asciimat(unicodes)</title>
+ <para>
+ <emphasis role="bold">Для скаляра или строки</emphasis>
+ <varname>unicodes</varname>,
+ <literal>asciimat(unicodes)</literal> эквивалентна
+ <literal>ascii(unicodes)</literal>.
+ Она возвращает символьные строки, чьи символы имеют указанные коды.
+ <warning>
+ Нули стоят для кода пустого символа <literal>""</literal>, поскольку
+ настоящий символ <literal>ascii(0)</literal> пока что не поддерживается
+ в Scilab 6.
+ </warning>
+ </para>
+ <para>
+ <emphasis role="bold">Для столбца, матрицы или гиперматрицы</emphasis>
+ <varname>unicodes</varname>, каждая строка <varname>unicodes</varname>
+ обрабатывается отдельно и строит отдельную символьную строку Scilab.
+ </para>
+ <para>
+ Все завершающие пробелы <literal>ascii(32)</literal> построенных
+ символьных строк отсекаются.
+ </para>
+ <para>
+ Наконец, <varname>text</varname> имеет размер <varname>unicodes</varname>,
+ за исключением <literal>size(text,2)==1</literal>.
+ </para>
+ </refsect3>
+ </refsection>
+ <refsection>
+ <title>Примеры</title>
+ <programlisting role="example"><![CDATA[
+asciimat([])
+asciimat("")
+asciimat(0)
+
+r = asciimat("A")
+asciimat(r)
+
+// Со СТРОКОЙ на входе:
+r = asciimat(["A" "BC"])
+asciimat(r)
+
+r = asciimat(["A" "" "BC"]) // "" в строках игнорируются
+asciimat(r)
+ ]]></programlisting>
+ <screen><![CDATA[
+--> asciimat([])
+ ans =
+ []
+--> asciimat("")
+ ans =
+ []
+--> asciimat(0)
+ ans =
+ ""
+
+--> r = asciimat("A")
+ r =
+ 65.
+--> asciimat(r)
+ ans =
+ "A"
+
+--> // With an input ROW:
+--> r = asciimat(["A" "BC"])
+ r =
+ 65. 66. 67.
+
+--> asciimat(r)
+ ans =
+ "ABC"
+
+--> r = asciimat(["A" "" "BC"]) // "" in rows are ignored
+ r =
+ 65. 66. 67.
+
+--> asciimat(r)
+ ans =
+ "ABC"
+]]></screen>
+ <para>
+ Со столбцом на входе:
+ </para>
+ <programlisting role="example"><![CDATA[
+asciimat(["" ; ""])
+asciimat((97:110)')'
+strsplit("a":"n")'
+
+r = asciimat(["ABC" ; "" ; "D"]) // Дополнение коротких строк с помощью 32
+asciimat(r)
+r = asciimat(["AB" ; "αβ"]) // используется 1-байтный код UTF-8
+asciimat(r) // завершающие пробелы ascii(32) отсекаются
+ ]]></programlisting>
+ <screen><![CDATA[
+--> asciimat(["" ; ""])
+ ans =
+ []
+
+--> asciimat((97:110)')'
+ ans =
+ "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
+
+--> strsplit("a":"n")'
+ ans =
+ "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
+
+--> r = asciimat(["ABC" ; "" ; "D"]) // Padding short rows with 32
+ r =
+ 65. 66. 67.
+ 32. 32. 32.
+ 68. 32. 32.
+
+--> asciimat(r)
+ ans =
+ "ABC"
+ ""
+ "D"
+
+--> r = asciimat(["AB" ; "αβ"]) // 1-byte UTF-8 coding is used
+ r =
+ 65. 66. 32. 32.
+ 206. 177. 206. 178.
+
+--> asciimat(r) // Trailing ascii(32) spaces are trimmed
+ ans =
+ "AB"
+ "αβ"
+]]></screen>
+ <para>
+ С двумерной матрицей на входе:
</para>
+ <programlisting role="example"><![CDATA[
+r = asciimat([" AB", " ", "CD " ; "α", "βγ", " "])
+asciimat(r)
+ ]]></programlisting>
+ <screen><![CDATA[
+--> r = asciimat([" AB", " ", "CD " ; "α", "βγ", " "])
+ r =
+ 32. 65. 66. 32. 67. 68. 32.
+ 206. 177. 206. 178. 206. 179. 32.
+
+--> asciimat(r)
+ ans =
+ " AB CD"
+ "αβγ"
+]]></screen>
+ <para>
+ С трёхмерной гиперматрицей на входе:
+ </para>
+ <programlisting role="example"><![CDATA[
+x = ["a €" "bδ " ; "" "" ; "" "" ];
+x2 = [" α" "βδc" ; "" "" ; "ε4" ""];
+h = cat(3, x, x2)
+r = asciimat(h)
+asciimat(r)
+ ]]></programlisting>
+ <screen><![CDATA[
+--> h = cat(3, x, x2)
+ h =
+(:,:,1)
+ "a €" "bδ "
+ "" ""
+ "" ""
+(:,:,2)
+ " α" "βδc"
+ "" ""
+ "ε4" ""
+
+--> r = asciimat(h)
+ r =
+(:,:,1)
+ 97. 32. 226. 130. 172. 98. 206. 180. 32.
+ 32. 32. 32. 32. 32. 32. 32. 32. 32.
+ 32. 32. 32. 32. 32. 32. 32. 32. 32.
+(:,:,2)
+ 32. 206. 177. 206. 178. 206. 180. 99. 32.
+ 32. 32. 32. 32. 32. 32. 32. 32. 32.
+ 206. 181. 52. 32. 32. 32. 32. 32. 32.
+
+--> asciimat(r)
+ ans =
+(:,:,1)
+ "a €bδ"
+ ""
+ ""
+(:,:,2)
+ " αβδc"
+ ""
+ "ε4"
+]]></screen>
</refsection>
+
<refsection role="see also">
<title>Смотрите также</title>
<simplelist type="inline">
<member>
<link linkend="ascii">ascii</link>
</member>
+ <member>
+ <link linkend="char">char</link>
+ </member>
</simplelist>
</refsection>
+
+ <refsection role="history">
+ <title>История</title>
+ <revhistory>
+ <revision>
+ <revnumber>6.1.1</revnumber>
+ <revdescription>
+ <itemizedlist>
+ <listitem>
+ Принимаются текстовые компоненты различной длины или/и
+ включая символы UTF-8. Реализовано дополнение кодами
+ ascii(" ")==32.
+ </listitem>
+ <listitem>
+ asciimat(unicodes) отсекает все завершающие пробелы.
+ </listitem>
+ <listitem>
+ Для любых гиперматрицы unicodes, r = asciimat(unicodes)
+ больше не сжимает size(r,2).
+ </listitem>
+ </itemizedlist>
+ </revdescription>
+ </revision>
+ </revhistory>
+ </refsection>
</refentry>
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) ???? - INRIA - Scilab
// Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
-// Copyright (C) 2017 - Samuel GOUGEON
-//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2017 - 2021 - Samuel GOUGEON
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// Returned value have same size as input value instead of second dims !
// Fonction created because ascii() Scilab function returns a row vector
+ y = []
if x==[] then
- y=[]
return
end
- dims = size(x);
if typeof(x) == "string" // convert string to ascii code
- if size(dims,"*") > 2 // hypermatrix case
- colref = 0;
- lastDim = dims($);
- dims($) = [];
- l=list();
- for i=1:size(dims,"*")
- l(i) = 1:$;
+ dims = size(x)
+ x = strcat(matrix(permute(x,[2 1 3:length(dims)]), dims(2), -1),"","r")'
+ tmp = ascii(1:127);
+ for c = ["\" "/" "]"]
+ tmp = strsubst(tmp, c, "\"+c);
+ end
+ kUTF = grep(x, "/[^" + tmp + "]/", "regexp")
+ if kUTF == [] then
+ L = length(x)
+ m = max(L)
+ if or(length(x)<>m) then
+ // Padding with spaces (like Octave, unlike Matlab)
+ x = part(x(:),1:m)
+ end
+ y = matrix(ascii(x)', [length(x(1)), dims(1), dims(3:$)])
+ y = permute(y, [2 1 3:length(dims)])
+ else
+ ext = []
+ for k = kUTF
+ a = ascii(x(k));
+ ext($+1,1:length(a)) = a;
end
- for i=1:lastDim
- res=asciimat(x(l(:), i));
- if colref == 0 then
- colref=size(res,"c");
- else
- if colref <> size(res,"c")
- msg = gettext("%s: Wrong input argument #%d: Inconsistent size.\n")
- error(msprintf(msg, "asciimat", 1));
- return
- end
- end
- y(l(:), i) = res;
+ ext(ext==0) = 32; // Padding with spaces
+
+ noUTF = x(:)
+ noUTF(kUTF) = ""
+ m = max(size(ext,2), max(length(noUTF)))
+ noUTF = part(noUTF, 1:m)
+ y = matrix(ascii(noUTF),m,-1)'
+ if size(ext,2)<m
+ ext(1,m) = 32 // extends a to m columns
end
- else // 2D matrix case | ["a" "bc";"de" "f"] => [97 98 99;100 101 102]
- x=x';
- a = ascii(x(:));
- aSize = size(a, "*");
- dims(2) = 1;
- p = prod(dims);
- if modulo(aSize, p)
- msg = gettext("%s: Wrong input argument #%d: Inconsistent size.\n")
- error(msprintf(msg, "asciimat", 1));
+ for i = 1:length(kUTF)
+ y(kUTF(i),:) = ext(i,:) ;
end
- dims(2) = dims(1);
- dims(1) = aSize/p;
- y = matrix(a, dims)';
+ y = permute(matrix(y',[m dims(1) dims(3:$)]), [2 1 3:length(dims)])
end
+
else // convert ascii codes to string
- x = permute(x,[2 1 3:ndims(x)]);
- y = ascii(x);
- Ly = length(y)
- rlength = Ly / (prod(dims)/dims(2))
- if dims(1)>1
- if modulo(Ly, rlength)
- msg = gettext("%s: Wrong input argument #%d: Inconsistent size.\n")
- error(msprintf(msg,"asciimat", 1))
- end
- y = strsplit(y, rlength:rlength:(Ly-1));
+ dims = size(x)
+ x = permute(x, [2 1 3:ndims(x)]);
+ x = matrix(x,size(x,1),-1);
+ // Tags the EOL:
+ for c = ascii("$€£")
+ x($+1,:) = c;
end
- y = matrix(y, [dims(1) dims(3:$)]);
+ //
+ x = matrix(x,1,-1)
+ // Any zero will block ascii(): http://bugzilla.scilab.org/15101
+ x(x==0) = [] // 0 <=> ""
+ x = [x, 65] // works around http://bugzilla.scilab.org/16686
+ y = strsplit(ascii(x), "$€£");
+ y($) = [] // removes the ending ascii(65)
+ y = matrix(y, [dims(1) 1 dims(3:$)]); // dims#2 not squeezed (Matlab, Octave)
+ y = stripblanks(y,%f,1) // Matlab & Octave trim trailing ascii(32)(not \t)
end
endfunction
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2017 - Samuel GOUGEON
+// Copyright (C) 2017-2021 - Samuel GOUGEON
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
assert_checkequal(asciimat(97:122), "abcdefghijklmnopqrstuvwxyz");
c = (97:122)';
-r = strsplit("a":"z",1:25);
-assert_checkequal(asciimat(c), r);
-assert_checkequal(asciimat(cat(3,c,c)), [r r]);
-assert_checkequal(asciimat(cat(7,c,c)), cat(6, r, r));
+C = strsplit("a":"z",1:25);
+assert_checkequal(asciimat(c), C);
+assert_checkequal(asciimat(cat(3,c,c)), cat(3,C,C));
+assert_checkequal(asciimat(cat(7,c,c)), cat(7,C,C));
// With UTF8 (limited application)
t = "àâãäéèêëìîïòôöùûü";
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
-// Copyright (C) 2017 - Samuel GOUGEON
+// Copyright (C) 2020-2021 - Samuel GOUGEON
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
// <-- CLI SHELL MODE -->
// <-- NO CHECK REF -->
-// ascii to string
-// ---------------
-ref = [97 98 99 ;100 101 102];
-code = asciimat(["a" "b" "c";"d" "e" "f"]);
-assert_checkequal(ref, code);
+// Empty
+assert_checkequal(asciimat([]), []);
+assert_checkequal(asciimat(["" ""]), []);
+assert_checkequal(asciimat(["";""]), []);
+assert_checkequal(asciimat(["" "";"" ""]), []);
-ref = [97 122 98 99 ;100 101 121 102];
-code = asciimat(["az" "b" "c";"d" "ey" "f"]);
-assert_checkequal(ref, code);
+// US-ASCII
+// ========
+// Scalar
+assert_checkequal(asciimat(""), []);
+assert_checkequal(asciimat("a"), 97);
+assert_checkequal(asciimat("abc"), 97:99);
+assert_checkequal(asciimat(0), "");
+assert_checkequal(asciimat(97), "a");
+assert_checkequal(asciimat(97:99), "abc");
-// 3D hypermat
-m = matrix(97:120,4,3,2);
-t = asciimat(m);
-ref = ["aei" "mqu"
- "bfj" "nrv"
- "cgk" "osw"
- "dhl" "ptx"
- ];
-assert_checkequal(t, ref);
+// Mat with all lengths equal
+t = ["ab" ; " c" ; "d "];
+ref = [ 97 98 ; 32 99 ; 100 32];
+assert_checkequal(asciimat(t), ref);
+assert_checkequal(asciimat(ref), ["ab" ; " c" ; "d"]);
-// 12D hypermat
-h = cat(12,m,m);
-t = asciimat(h);
-assert_checkequal(t, cat(11,ref,ref));
-
-// string to ascii
-// ---------------
-// not managed in scilab 5
-scilabversion = getversion("scilab");
-if scilabversion(1) >= 6
- ref = matrix(97:120,2,3,4);
- a = matrix(strsplit(ascii(97:120),1:23),2,3,4);
- code = asciimat(a);
- assert_checkequal(ref, code);
-end
-//
-ref = ["azerty";"ytreza"];
-str = asciimat([97 122 101 114 116 121; 121 116 114 101 122 97]);
-assert_checkequal(ref, str);
+t = ["a" "b" "c" ; "d" "e" "f"];
+ref = [ 97 98 99 ;
+ 100 101 102];
+assert_checkequal(asciimat(t), ref);
+assert_checkequal(asciimat(ref), ["abc" ; "def"]);
+
+// Matrix with various lengths, including "" :
+// * Matlab & Octave DELETE ""
+// * Octave PADDS with ascii(32)
+t = ["a" ; "ab" ; ""; " " ; "ab d"];
+ref = [ 97 32 32 32
+ 97 98 32 32
+ 32 32 32 32
+ 32 32 32 32
+ 97 98 32 100 ];
+assert_checkequal(asciimat(t), ref);
+ // Matlab and Octave trim trailing spaces ascii(32)
+assert_checkequal(asciimat(ref), ["a"; "ab"; "" ; "" ; "ab d"]);
+
+// Hypermat
+t = [t, flipdim(t,1)];
+t = cat(3, t,t);
+ref = [97,97,98,32,100;97,98,32,32,32;32,32,32,32,32;32,32,97,98,32;97,98,32,100,97];
+ref = cat(3, ref, ref);
+assert_checkequal(asciimat(t), ref);
+tmp = ["aab d" ; "ab" ; "" ; " ab" ; "ab da"];
+assert_checkequal(asciimat(ref), cat(3, tmp,tmp));
-ref = ["bdf" "hjl" "npr" "tvx";"ceg" "ikm" "oqs" "uwy"];
-a = matrix(97+(1:2*3*4),2,3,4);
-str = asciimat(a);
-assert_checkequal(ref, str);
+// UTF-8
+// =====
+// ascimmat() uses Octave's encoding = UTF-8 + trims trailing spaces
+t1 = "àâãäéèêë";
+t2 = "ìîïòôöùûü";
+assert_checkequal(asciimat(asciimat(t2)), t2);
+assert_checkequal(asciimat(asciimat([t1 t2])), t1+t2);
+assert_checkequal(asciimat(asciimat([t1 ; t2])), [t1 ; t2]);
+assert_checkequal(asciimat(asciimat([t1 t2 ; t2 t1])), [t1+t2 ; t2+t1]);
-// With UTF8 (limited application)
-t = "àâãäéèêëìîïòôöùûü";
-assert_checkequal(asciimat(asciimat(t)), t);
-assert_checkequal(asciimat(asciimat([t t])), t+t);
-assert_checkequal(asciimat(asciimat([t;t])), [t;t]);
+// Scalar
+assert_checkequal(asciimat("α"), [206 177]);
+assert_checkequal(asciimat("βcδ"), [206 178 99 206 180]);
+assert_checkequal(asciimat("abc"), 97:99);
+x = ["a €" "bδ " ; " " "45ε"]
+// for x(:)
+ref = [97 32 226 130 172
+ 32 32 32 32 32
+ 98 206 180 32 32
+ 52 53 206 181 32 ];
+assert_checkequal(asciimat(x(:)), ref);
+assert_checkequal(asciimat(ref), ["a €" "" "bδ" "45ε"]');
+// for x matrix
+ref = [97 32 226 130 172 98 206 180 32
+ 32 32 32 52 53 206 181 32 32 ];
+assert_checkequal(asciimat(x), ref);
+assert_checkequal(asciimat(ref), ["a €bδ" ; " 45ε"]);
+
+// 3D hypermat
+x2 = ["αab" "βδc" ; "ε4" ""];
+h = cat(3, x, x2)
+/* h =
+(:,:,1)
+ "a €" "bδ "
+ " " "45ε"
+(:,:,2)
+ "αab" "βδc"
+ "ε4" ""
+*/
+ref = cat(3, [97 32 226 130 172 98 206 180 32.
+ 32 32 32 52 53 206 181 32 32 ],..
+ [206 177 97 98 206 178 206 180 99
+ 206 181 52 32 32 32 32 32 32 ]);
+assert_checkequal(asciimat(h), ref);
+refS = cat(3,["a €bδ";" 45ε"],["αabβδc";"ε4"]);
+assert_checkequal(asciimat(ref), refS);
+
+// 12D hypermat
+h = cat(12, ["€" "bδ"], ["" "45ε"]);
+ref = cat(12, [226 130 172 98 206 180 ],..
+ [ 52 53 206 181 32 32 ]);
+assert_checkequal(asciimat(h), ref);
+assert_checkequal(asciimat(ref), cat(12,"€bδ","45ε"));