Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@prog/strpad.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function varargout = strpad(varargin) | |
2 % STRPAD Pads a string with blank spaces until it is N characters long. | |
3 % | |
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
5 % | |
6 % DESCRIPTION: STRPAD Pads a string with blank spaces until it is N characters | |
7 % long. If s is already N characters long (or longer) then the | |
8 % string is truncated. | |
9 % | |
10 % CALL: so = strpad('Pads this string to 30 characters', 30) | |
11 % so = strpad('Pads this string to 30 characters', [10 30]) | |
12 % so = strpad('Pads this string with = characters', [10 30], '=') | |
13 % | |
14 % INPUTS: s - string | |
15 % N - length of the string. If you give two values here, then | |
16 % the string is padded at the front and back. | |
17 % c - pad with this string/character. Default is ' '. | |
18 % | |
19 % OUTPUTS: so - the padded string | |
20 % | |
21 % VERSION: $Id: strpad.m,v 1.3 2008/08/19 15:43:15 hewitson Exp $ | |
22 % | |
23 % HISTORY: 27-04-2007 M Hewitson | |
24 % Creation | |
25 % | |
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
27 | |
28 c = ''; | |
29 if nargin == 2 | |
30 s = varargin{1}; | |
31 N = varargin{2}; | |
32 elseif nargin == 3 | |
33 s = varargin{1}; | |
34 N = varargin{2}; | |
35 c = varargin{3}; | |
36 else | |
37 help(mfilename); | |
38 error('### Incorrect inputs'); | |
39 end | |
40 | |
41 if isempty(c) | |
42 c = ' '; | |
43 end | |
44 | |
45 if numel(N) == 2 | |
46 while length(s) < sum(N) | |
47 s = [c s c]; | |
48 end | |
49 else | |
50 while length(s) < N | |
51 s = [s c]; | |
52 end | |
53 end | |
54 % Set output | |
55 varargout{1} = s; | |
56 % END |