Mercurial > octave
comparison scripts/strings/dec2bin.m @ 13167:f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
* dec2base.m, dec2bin.m, dec2hex.m: Allow cellstr inputs.
Amend documentation for new feature and add test for new behavior.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 19 Sep 2011 18:03:43 -0700 |
parents | fd0a3ac60b0e |
children | 72c96de7a403 |
comparison
equal
deleted
inserted
replaced
13164:36afcd6fc45f | 13167:f7cb824dc8c0 |
---|---|
26 ## dec2bin (14) | 26 ## dec2bin (14) |
27 ## @result{} "1110" | 27 ## @result{} "1110" |
28 ## @end group | 28 ## @end group |
29 ## @end example | 29 ## @end example |
30 ## | 30 ## |
31 ## If @var{d} is a vector, returns a string matrix, one row per value, | 31 ## If @var{d} is a matrix or cell array, return a string matrix with one |
32 ## padded with leading zeros to the width of the largest value. | 32 ## row per element in @var{d}, padded with leading zeros to the width of |
33 ## the largest value. | |
33 ## | 34 ## |
34 ## The optional second argument, @var{len}, specifies the minimum | 35 ## The optional second argument, @var{len}, specifies the minimum |
35 ## number of digits in the result. | 36 ## number of digits in the result. |
36 ## @seealso{bin2dec, dec2base, dec2hex} | 37 ## @seealso{bin2dec, dec2base, dec2hex} |
37 ## @end deftypefn | 38 ## @end deftypefn |
49 print_usage (); | 50 print_usage (); |
50 endif | 51 endif |
51 | 52 |
52 endfunction | 53 endfunction |
53 | 54 |
54 %!assert(strcmp (dec2bin (14), "1110")); | 55 |
55 %!assert(strcmp (dec2bin (14, 6), "001110")); | 56 %!assert(dec2bin (14), "1110"); |
57 %!assert(dec2bin (14, 6), "001110"); | |
58 %!assert(dec2bin ({1, 2; 3, 4}), ["001"; "011"; "010"; "100"]); | |
56 | 59 |
57 %%Test input validation | 60 %%Test input validation |
58 %!error dec2bin (); | 61 %!error dec2bin (); |
59 %!error dec2bin (1, 2, 3); | 62 %!error dec2bin (1, 2, 3); |
60 | 63 |