1 # Created by Octave 3.6.1, Mon Apr 02 13:25:55 2012 UTC <root@brouzouf>
13 # name: <cell-element>
17 -- Loadable Function: RETURN_VALUE = apply
18 (@FUNCTION_HANDLE,CELL_ARRAY_OF_ARGS)
19 -- Loadable Function: RETURN_VALUE = apply (@FUNCTION_HANDLE)
20 Apply calls the function FUNCTION_HANDLE with the arguments of the
21 cell array CELL_ARRAY_OF_ARGS which contains the actual arguments
22 arg1,arg2,..., argn to the function, in that order. Apply invokes
23 the function as FUNCTION_HANDLE(arg1, arg2, ... ,argn), where the
24 arguments are extracted from each elements of the 1-row cell array
27 _warning_: `apply' has been deprecated in favor of `arrayfun' and
28 `cellfun' for arrays and cells respectively. This function will be
29 removed from future versions of the 'miscellaneous' package".
31 Apply also works on array of function handles if FUNCTION_HANDLE
32 is passed as a cell array of a handles; in this case apply,
33 evaluates each function (using the handle) with the same arguments.
35 The cell-array argument is optional second argument, in the form
36 of a 1-row with multiple elements. The elements of the cell-array
37 form the actual arguments supplied when invoking the function
40 The return value depends on the function invoked, and the validity
43 z=apply(@sqrt,cell([1,2; 3,4]));
44 z=apply(@apply,cell(@sqrt,cell([1,2; 3,4])));
45 apply(@sum,cell([1,2,3,4]))
46 apply(@max,cell([1,2,3,4]))
47 apply(@min,cell([1,2,3,4]))
49 In first case, apply computes the sqrt of the matrix [1,2; 3,4];
50 The second example is meta-apply, using apply on itself. The rest
51 of the examples invoke sum, max, min respectively.
56 # name: <cell-element>
60 Apply calls the function FUNCTION_HANDLE with the arguments of the cell
65 # name: <cell-element>
72 # name: <cell-element>
76 -- Function: [STRING] = asci ([COLUMNS])
79 If this function is called without any input argument and without
80 any output argument then print a nice ASCI-table (excluding
81 special characters with hexcode 0x00 to 0x20) on screen with four
82 columns per default. If this function is called with one output
83 argument then return an ASCI-table string and don't print anything
84 on screen. Finally, if this function is called with one input
85 argument of type scalar then either print (no output argument) or
86 return (one output argument) an ASCI-table with a number of
87 columns given in COLUMNS.
96 # name: <cell-element>
104 # name: <cell-element>
111 # name: <cell-element>
115 -- Function File: COEFS= chebyshevpoly (KIND,ORDER,X)
116 Compute the coefficients of the Chebyshev polynomial, given the
117 ORDER. We calculate the Chebyshev polynomial using the recurrence
118 relations, Tn+1(x) = (2*x*Tn(x) - Tn-1(x)). The KIND can set to
119 compute the first or second kind chebyshev polynomial.
121 If the value X is specified, the polynomial is also evaluated,
122 otherwise just the return the coefficients of the polynomial are
125 This is NOT the generalized Chebyshev polynomial.
131 # name: <cell-element>
135 Compute the coefficients of the Chebyshev polynomial, given the ORDER.
139 # name: <cell-element>
146 # name: <cell-element>
150 -- Function File: X = clip (X)
151 -- Function File: X = clip (X, HI)
152 -- Function File: X = clip (X, [LO, HI])
153 Clip X values outside the range.to the value at the boundary of the
156 Range boundaries, LO and HI, default to 0 and 1 respectively.
158 X = clip (X) Clip to range [0, 1]
160 X = clip (X, HI) Clip to range [0, HI]
162 X = clip (X, [LO, HI]) Clip to range [LO, HI]
167 # name: <cell-element>
171 Clip X values outside the range.
175 # name: <cell-element>
182 # name: <cell-element>
186 -- Function File: colorboard (M, PALETTE, OPTIONS)
187 Displays a color board corresponding to a numeric matrix M. M
188 should contain zero-based indices of colors. The available range
189 of indices is given by the PALETTE argument, which can be one of
192 * "b&w" Black & white, using reverse video mode. This is the
193 default if M is logical.
195 * "ansi8" The standard ANSI 8 color palette. This is the
196 default unless M is logical.
198 * "aix16" The AIXTerm extended 16-color palette. Uses codes
199 100:107 for bright colors.
201 * "xterm16" The first 16 system colors of the Xterm 256-color
204 * "xterm216" The 6x6x6 color cube of the Xterm 256-color
205 palette. In this case, matrix can also be passed as a
206 MxNx3 RGB array with values 0..5.
208 * "grayscale" The 24 grayscale levels of the Xterm 256-color
211 * "xterm256" The full Xterm 256-color palette. The three
212 above palettes together.
214 OPTIONS comprises additional options. The recognized options are:
216 * "indent" The number of spaces by which the board is
219 * "spaces" The number of spaces forming one field. Default 2.
221 * "horizontalseparator" The character used for horizontal
222 separation of the table. Default "#".
224 * "verticalseparator" The character used for vertical
225 separation of the table. Default "|".
230 # name: <cell-element>
234 Displays a color board corresponding to a numeric matrix M.
238 # name: <cell-element>
245 # name: <cell-element>
249 Creates a latex file from a csv file. The generated latex file contains a
250 tabular with all values of the csv file. The tabular can be decorated with
251 row and column titles. The generated latex file can be inserted in any latex
252 document by using the '\input{latex file name without .tex}' statement.
255 - csv2latex(csv_file, csv_sep, latex_file)
256 - csv2latex(csv_file, csv_sep, latex_file, tabular_alignments)
257 - csv2latex(csv_file, csv_sep, latex_file, tabular_alignments, has_hline)
258 - csv2latex(csv_file, csv_sep, latex_file,
259 tabular_alignments, has_hline, column_titles)
260 - csv2latex(csv_file, csv_sep, latex_file, tabular_alignments,
261 has_hline, column_titles, row_titles)
264 csv_file - the path to an existing csv file
265 csv_sep - the seperator of the csv values
266 latex_file - the path of the latex file to create
267 tabular_alignments - the tabular alignment preamble (default = {'l','l',...})
268 has_hline - indicates horizontal line seperator (default = false)
269 column_titles - array with the column titles of the tabular (default = {})
270 row_titles - array with the row titles of the tabular (default = {})
273 # creates the latex file 'example.tex' from the csv file 'example.csv'
274 csv2latex("example.csv", '\t', "example.tex");
276 # creates the latex file with horizontal and vertical lines
277 csv2latex('example.csv', '\t', 'example.tex', {'|l|', 'l|'}, true);
279 # creates the latex file with row and column titles
280 csv2latex('example.csv', '\t', 'example.tex', {'|l|', 'l|'}, true,
281 {'Column 1', 'Column 2', 'Column 3'}, {'Row 1', 'Row 2'});
285 # name: <cell-element>
289 Creates a latex file from a csv file.
293 # name: <cell-element>
300 # name: <cell-element>
304 -- Function File: B = gameoflife (A, ngen, delay)
305 Runs the Conways' game of life from a given initial state for a
306 given number of generations and visualizes the process. If ngen
307 is infinity, the process is run as long as A changes. Delay sets
308 the pause between two frames. If zero, visualization is not done.
313 # name: <cell-element>
317 Runs the Conways' game of life from a given initial state for a given
322 # name: <cell-element>
329 # name: <cell-element>
333 -- Function File: COEFS= hermitepoly (ORDER,X)
334 Compute the coefficients of the Hermite polynomial, given the
335 ORDER. We calculate the Hermite polynomial using the recurrence
336 relations, Hn+1(x) = 2x.Hn(x) - 2nHn-1(x).
338 If the value X is specified, the polynomial is also evaluated,
339 otherwise just the return the coefficients.
345 # name: <cell-element>
349 Compute the coefficients of the Hermite polynomial, given the ORDER.
353 # name: <cell-element>
360 # name: <cell-element>
364 -- Function file: X, Y hilbert_curve (N)
365 Creates an iteration of the Hilbert space-filling curve with N
366 points. The argument N must be of the form `2^M', where M is an
367 integer greater than 0.
370 [x ,y] = hilbert_curve (n);
371 line (x, y, "linewidth", 4, "color", "blue");
377 # name: <cell-element>
381 Creates an iteration of the Hilbert space-filling curve with N points.
385 # name: <cell-element>
392 # name: <cell-element>
396 -- Function File: infoskeleton (PROTOTYPE, INDEX_STR, SEE_ALSO)
397 Generate TeXinfo skeleton documentation of PROTOTYPE.
399 Optionally INDEX_STR and SEE_ALSO can be specified.
401 Usage of this function is typically,
402 infoskeleton('[V,Q] = eig( A )','linear algebra','eigs, chol, qr, det')
410 # name: <cell-element>
414 Generate TeXinfo skeleton documentation of PROTOTYPE.
418 # name: <cell-element>
425 # name: <cell-element>
429 -- Function File: COEFS= laguerrepoly (ORDER,X)
430 Compute the coefficients of the Laguerre polynomial, given the
431 ORDER. We calculate the Laguerre polynomial using the recurrence
432 relations, Ln+1(x) = inv(n+1)*((2n+1-x)Ln(x) - nLn-1(x)).
434 If the value X is specified, the polynomial is also evaluated,
435 otherwise just the return the coefficients of the polynomial are
438 This is NOT the generalized Laguerre polynomial.
444 # name: <cell-element>
448 Compute the coefficients of the Laguerre polynomial, given the ORDER.
452 # name: <cell-element>
459 # name: <cell-element>
463 -- Function File: A = lauchli (N)
464 -- Function File: A = lauchli (N,MU)
465 Creates the matrix [ ones(1,N); MU*eye(N) ] The value MU defaults
466 to sqrt(eps). This is an ill-conditioned system for testing the
467 accuracy of the QR routine.
472 norm(Q'*Q - eye(rows(Q)))
474 See also: ones, zeros, eye
479 # name: <cell-element>
483 Creates the matrix [ ones(1,N); MU*eye(N) ] The value MU defaults to
488 # name: <cell-element>
495 # name: <cell-element>
499 -- Function File: COEFS= legendrepoly (ORDER,X)
500 Compute the coefficients of the Legendre polynomial, given the
501 ORDER. We calculate the Legendre polynomial using the recurrence
502 relations, Pn+1(x) = inv(n+1)*((2n+1)*x*Pn(x) - nPn-1(x)).
504 If the value X is specified, the polynomial is also evaluated,
505 otherwise just the return the coefficients of the polynomial are
508 This is NOT the generalized Legendre polynomial.
514 # name: <cell-element>
518 Compute the coefficients of the Legendre polynomial, given the ORDER.
522 # name: <cell-element>
529 # name: <cell-element>
533 -- Function File: RESULT = map (FUNCTION, ITERABLE, ...)
534 Apply FUNCTION to every item of ITERABLE and return the results.
536 `map', like Lisp's ( & numerous other language's ) function for
537 iterating the result of a function applied to each of the data
538 structure's elements in turn. The results are stored in the
539 corresponding input's place. For now, just will work with cells and
540 matrices, but support for structs are intended for future versions.
541 Also, only "prefix" functions ( like `min (a, b, c, ...)' ) are
542 supported. FUN_HANDLE can either be a function name string or a
543 function handle (recommended).
563 octave> map(@min,A,B)
572 See also: reduce, match
578 # name: <cell-element>
582 Apply FUNCTION to every item of ITERABLE and return the results.
586 # name: <cell-element>
593 # name: <cell-element>
597 -- Function File: RESULT = match ( FUN_HANDLE, ITERABLE )
598 match is filter, like Lisp's ( & numerous other language's )
599 function for Python has a built-in filter function which takes two
600 arguments, a function and a list, and returns a list. 'match'
601 performs the same operation like filter in Python. The match
602 applies the function to each of the element in the ITERABLE and
603 collects that the result of a function applied to each of the data
604 structure's elements in turn, and the return values are collected
605 as a list of input arguments, whenever the function-result is
606 'true' in Octave sense. Anything (1,true,?) evaluating to true,
607 the argument is saved into the return value.
609 FUN_HANDLE can either be a function name string or a function
610 handle (recommended).
612 Typically you can use it as,
613 match(@(x) ( x >= 1 ), [-1 0 1 2])
616 See also: reduce, cellfun, arrayfun, cellfun, structfun, spfun
622 # name: <cell-element>
626 match is filter, like Lisp's ( & numerous other language's ) function
631 # name: <cell-element>
638 # name: <cell-element>
642 -- Function File: X = normc (M)
643 Normalize the columns of a matrix to a length of 1 and return the
660 # name: <cell-element>
664 Normalize the columns of a matrix to a length of 1 and return the
669 # name: <cell-element>
676 # name: <cell-element>
680 -- Function File: X = normr (M)
681 Normalize the rows of a matrix to a length of 1 and return the
698 # name: <cell-element>
702 Normalize the rows of a matrix to a length of 1 and return the matrix.
706 # name: <cell-element>
713 # name: <cell-element>
717 -- Function File: [Y, F] = nze (X)
718 Extract nonzero elements of X. Equivalent to `X(X != 0)'.
719 Optionally, returns also linear indices.
724 # name: <cell-element>
728 Extract nonzero elements of X.
732 # name: <cell-element>
739 # name: <cell-element>
743 -- Function file: X, Y peano_curve (N)
744 Creates an iteration of the Peano space-filling curve with N
745 points. The argument N must be of the form `3^M', where M is an
746 integer greater than 0.
749 [x, y] = peano_curve (n);
750 line (x, y, "linewidth", 4, "color", "red");
756 # name: <cell-element>
760 Creates an iteration of the Peano space-filling curve with N points.
764 # name: <cell-element>
771 # name: <cell-element>
775 -- Function File: publish (FILENAME)
776 -- Function File: publish (FILENAME, OPTIONS)
777 Produces latex reports from scripts.
781 where the argument is a string that contains the file name of the
782 script we want to report.
784 If two arguments are given, they are interpreted as follows.
786 publish (FILENAME, [OPTION, VALUE, ...])
788 The following options are available:
792 the only available format values are the strings `latex' and
797 string that specifies the image format, valid formats are
798 `pdf', `png', and `jpg'(or `jpeg').
802 boolean value that specifies if the source code will be
803 included in the report.
807 boolean value that specifies if execution results will be
808 included in the report.
824 * Any additional non-valid field is removed without
827 * To include several figures in the resulting report you must
828 use figure with a unique number for each one of them.
830 * You do not have to save the figures manually, publish will do
833 * The functions works only for the current path and no way ...
834 to specify other path is allowed.
837 Assume you have the script `myscript.m' which looks like
846 You can then call publish with default OPTIONS
853 # name: <cell-element>
857 Produces latex reports from scripts.
861 # name: <cell-element>
868 # name: <cell-element>
872 -- Function File: [OP,NREAD] = read_options ( args, varargin )
873 The function read_options parses arguments to a function as,
874 [ops,nread] = read_options (args,...) - Read options
876 The input being ARGS a list of options and values. The options
877 can be any of the following,
879 'op0' , string : Space-separated names of opt taking no
882 'op1' , string : Space-separated names of opt taking one
885 'extra' , string : Name of nameless trailing arguments.
888 'default', struct : Struct holding default option values
891 'prefix' , int : If false, only accept whole opt names.
892 Otherwise, <0> recognize opt from first chars,
893 and choose shortest if many opts start alike.
895 'nocase' , int : If set, ignore case in option names
898 'quiet' , int : Behavior when a non-string or unknown opt is
899 met <0> 0 - Produce an error 1 -
900 Return quietly (can be diagnosed by checking 'nread')
902 'skipnan', int : Ignore NaNs if there is a default value.
903 Note : At least one of 'op0' or 'op1' should be specified.
905 The output variables are, OPS : struct : Struct whose
906 key/values are option names/values NREAD : int : Number of
907 elements of args that were read
910 # Define options and defaults
911 op0 = "is_man is_plane flies"
912 default = struct ("is_man",1, "flies",0);
916 s = read_options (list (all_va_args), "op0",op0,"default",default)
918 # Create variables w/ same name as options
920 [is_man, is_plane, flies] = getfields (s,"is_man", "is_plane", "flies")
921 pre 2.1.39 function [op,nread] = read_options (args, ...)
926 # name: <cell-element>
930 The function read_options parses arguments to a function as,
935 # name: <cell-element>
942 # name: <cell-element>
946 -- Function File: X = reduce (FUNCTION, SEQUENCE,INITIALIZER)
947 -- Function File: X = reduce (FUNCTION, SEQUENCE)
948 Implements the 'reduce' operator like in Lisp, or Python. Apply
949 function of two arguments cumulatively to the items of sequence,
950 from left to right, so as to reduce the sequence to a single
951 value. For example, reduce(@(x,y)(x+y), [1, 2, 3, 4, 5])
952 calculates ((((1+2)+3)+4)+5). The left argument, x, is the
953 accumulated value and the right argument, y, is the update value
954 from the sequence. If the optional initializer is present, it is
955 placed before the items of the sequence in the calculation, and
956 serves as a default when the sequence is empty. If initializer is
957 not given and sequence contains only one item, the first item is
962 reduce(@(x,y)(x*y),[1:7])
963 => 5040 (actually, 7!)
968 # name: <cell-element>
972 Implements the 'reduce' operator like in Lisp, or Python.
976 # name: <cell-element>
983 # name: <cell-element>
987 -- Function File: rolldices (N)
988 -- Function File: rolldices (N, NREP, DELAY)
989 Returns N random numbers from the 1:6 range, displaying a visual
992 NREP sets the number of rolls, DELAY specifies time between
993 successive rolls in seconds. Default is nrep = 25 and delay = 0.1.
995 Requires a terminal with ANSI escape sequences enabled.
1000 # name: <cell-element>
1004 Returns N random numbers from the 1:6 range, displaying a visual
1009 # name: <cell-element>
1016 # name: <cell-element>
1020 -- Function File: S = slurp_file ( f )
1021 slurp_file return a whole text file F as a string S.
1023 F : string : filename S : string : contents of the file
1025 If F is not an absolute filename, and is not an immediately
1026 accessible file, slurp_file () will look for F in the path.
1031 # name: <cell-element>
1035 slurp_file return a whole text file F as a string S.
1039 # name: <cell-element>
1046 # name: <cell-element>
1050 -- Function File: [ X, NTRIAL] = solvesudoku (S)
1051 Solves a classical 9x9 sudoku. S should be a 9x9 array with
1052 numbers from 0:9. 0 indicates empty field. Returns the filled
1053 table or empty matrix if no solution exists. If requested, NTRIAL
1054 returns the number of trial-and-error steps needed.
1059 # name: <cell-element>
1063 Solves a classical 9x9 sudoku.
1067 # name: <cell-element>
1074 # name: <cell-element>
1078 -- Function File: N = temp_name ( rootname, quick )
1079 name = temp_name(rootname, quick=1) - Return a name that is not
1082 Returns a name, suitable for defining a new function, script or
1083 global variable, of the form
1087 Default rootname is "temp_name_"
1089 "quick" is an optional parameter, which defaults to 1. If it is
1090 false, temp_name() will find the smallest acceptable number for
1091 the name. Otherwise, a hopefully quicker method is used.
1097 # name: <cell-element>
1101 name = temp_name(rootname, quick=1) - Return a name that is not used
1106 # name: <cell-element>
1113 # name: <cell-element>
1117 -- Function File: units (FROMUNIT, TOUNIT)
1118 -- Function File: units (FROMUNIT, TOUNIT, X)
1119 Return the conversion factor from FROMUNIT to TOUNIT measurements.
1121 This is an octave interface to the *GNU Units* program which comes
1122 with an annotated, extendable database defining over two thousand
1123 measurement units. See `man units' or
1124 `http://www.gnu.org/software/units' for more information. If the
1125 optional argument X is supplied, return that argument multiplied
1126 by the conversion factor. Nonlinear conversions such as
1127 Fahrenheit to Celsius are not currently supported. For example, to
1128 convert three values from miles per hour into meters per second:
1130 units ("mile/hr", "m/sec", [30, 55, 75])
1133 13.411 24.587 33.528
1138 # name: <cell-element>
1142 Return the conversion factor from FROMUNIT to TOUNIT measurements.
1146 # name: <cell-element>
1153 # name: <cell-element>
1157 -- Function file: X, Y z_curve (N)
1158 Creates an iteration of the Z-order space-filling curve with N
1159 points. The argument N must be of the form `2^M', where M is an
1160 integer greater than 0.
1163 [x ,y] = z_curve (n);
1164 line (x, y, "linewidth", 4, "color", "blue");
1170 # name: <cell-element>
1174 Creates an iteration of the Z-order space-filling curve with N points.
1178 # name: <cell-element>
1185 # name: <cell-element>
1189 -- Function File: zagzig (MTRX)
1190 Returns zagzig walk-off of the elements of MTRX. Essentially it
1191 walks the matrix in a Z-fashion.
1193 mat = 1 4 7 2 5 8 3 6 9 then zagzag(mat) gives
1194 the output, [1 4 2 3 5 7 8 6 9], by walking as shown in the figure
1195 from pt 1 in that order of output. The argument MTRX should be a
1196 MxN matrix. One use of zagzig the use with picking up DCT
1197 coefficients like in the JPEG algorithm for compression.
1199 An example of zagzig use:
1200 mat = reshape(1:9,3,3);
1202 ans =[1 4 2 3 5 7 8 6 9]
1210 # name: <cell-element>
1214 Returns zagzig walk-off of the elements of MTRX.
1218 # name: <cell-element>
1225 # name: <cell-element>
1229 -- Function File: zigzag (MTRX)
1230 Returns zigzag walk-off of the elements of MTRX. Essentially it
1231 walks the matrix in a Z-fashion.
1233 mat = 1 4 7 2 5 8 3 6 9 then zigzag(mat) gives
1234 the output, [1 2 4 7 5 3 6 8 9], by walking as
1235 shown in the figure from pt 1 in that order of output. The
1236 argument MTRX should be a MxN matrix
1238 An example of zagzig use:
1239 mat = reshape(1:9,3,3);
1241 ans =[1 2 4 7 5 3 6 8 9]
1249 # name: <cell-element>
1253 Returns zigzag walk-off of the elements of MTRX.