Mercurial > hg > ltpda
comparison testing/utp_1.1/utp_fcns/get_random_unit.m @ 44:409a22968d5e default
Add unit tests
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 18:42:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
43:bc767aaa99a8 | 44:409a22968d5e |
---|---|
1 % GET_RANDOM_UNIT returns a random unit object, with random unit and random | |
2 % prefix (if the unit is different from '') | |
3 % | |
4 % CALL: u = get_test_ples | |
5 % | |
6 % OUTPUTS: u - a unit object with random unit and prefix | |
7 % | |
8 % VERSION: $Id: get_random_unit.m,v 1.2 2010/05/05 04:21:52 mauro Exp $ | |
9 % | |
10 function u = get_random_unit(varargin) | |
11 unit_list = unit.supportedUnits; | |
12 prefix_list = unit.supportedPrefixes; | |
13 | |
14 u = cell2mat(utils.math.randelement(unit_list,1)); | |
15 | |
16 pref = true; | |
17 if nargin | |
18 switch varargin{1} | |
19 case {'nopref', 'noprefix', 'no_pref', 'no_prefix'} | |
20 pref = false; | |
21 otherwise | |
22 end | |
23 end | |
24 | |
25 % Add a prefix only if the unit is different from '' | |
26 if pref && ~isempty(u) && ~strcmpi(u, '') | |
27 u = unit([cell2mat(utils.math.randelement(prefix_list,1)) u]); | |
28 else | |
29 u = unit(u); | |
30 end | |
31 | |
32 end |