Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@prog/yes2true.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 out = yes2true(in) | |
2 % YES2TRUE converts strings containing 'yes'/'no' into boolean true/false | |
3 % | |
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
5 % | |
6 % DESCRIPTION: YES2TRUE converts: | |
7 % - strings containing 'yes'/'no' into boolean true/false | |
8 % - strings containing 'true'/'false' into boolean true/false | |
9 % - double containing 1/0/-1 etc into boolean true/false | |
10 % | |
11 % CALL: out = yes2true(in) | |
12 % | |
13 % INPUTS: in - the variable to scan (may be a boolean, a double, or a | |
14 % string) | |
15 % | |
16 % OUTPUTS: out - a boolean value calculated according to the following | |
17 % table: | |
18 % INPUT CLASS INPUT VALUE OUTPUT VALUE | |
19 % boolean true true | |
20 % boolean false false | |
21 % string 'true' true | |
22 % string 'false' false | |
23 % string 'yes' true | |
24 % string 'no' false | |
25 % double >= 1 true | |
26 % double <= 0 false | |
27 % empty empty false | |
28 % | |
29 % EXAMPLE: >> pl = plist('variance', 'yes'); | |
30 % >> v = find(pl, 'variance'); | |
31 % >> yes2true(v) | |
32 % ans = | |
33 % 1 | |
34 % | |
35 % VERSION: $Id: yes2true.m,v 1.3 2010/03/23 14:31:27 mauro Exp $ | |
36 % | |
37 % HISTORY: 29-04-2009 M Hueller | |
38 % Creation | |
39 % | |
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
41 | |
42 if isempty(in) | |
43 out = false; | |
44 elseif ischar(in) | |
45 switch lower(in) | |
46 case {'yes', 'true', 'on', 'y', '1'} | |
47 out = true; | |
48 case {'no', 'false', 'off', 'n', '0', '-1'} | |
49 out = false; | |
50 otherwise | |
51 error('Unknown option %s', in); | |
52 end | |
53 elseif isfloat(in) | |
54 out = (in > 0); | |
55 elseif islogical(in) | |
56 out = in; | |
57 else | |
58 error('Unsupported type %s', class(in)); | |
59 end | |
60 | |
61 % END |