Mercurial > hg > ltpda
comparison m-toolbox/classes/@unit/char.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 % CHAR convert a unit object into a string. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: CHAR convert a unit object into a string. | |
5 % | |
6 % CALL: string = char(unit) | |
7 % | |
8 % VERSION: $Id: char.m,v 1.11 2011/02/18 16:48:55 ingo Exp $ | |
9 % | |
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
11 | |
12 function str = char(v) | |
13 str = ' '; | |
14 for jj=1:numel(v) | |
15 NDimensions = numel(v(jj).strs); | |
16 if NDimensions == 0 | |
17 nameString = '[]'; | |
18 else | |
19 nameString = ''; | |
20 for nd = 1:NDimensions | |
21 if(v(jj).exps(nd)~=0) | |
22 prefix = unit.val2prefix(v(jj).vals(nd)); | |
23 [n,d] = rat(v(jj).exps(nd)); | |
24 if(d==1) | |
25 if v(jj).exps(nd) ~=1 | |
26 nameString = sprintf('%s[%s%s^(%g)]', nameString,prefix,v(jj).strs{nd},v(jj).exps(nd)); | |
27 else | |
28 nameString = sprintf('%s[%s%s]',nameString,prefix,v(jj).strs{nd}); | |
29 end | |
30 else | |
31 nameString = sprintf('%s[%s%s^(%g/%g)]',nameString,prefix,v(jj).strs{nd},n,d); | |
32 end | |
33 else | |
34 nameString = sprintf('%s[]',nameString); | |
35 end | |
36 end | |
37 end | |
38 str_loop = strrep(nameString, '][', ' '); | |
39 str = [str, str_loop]; | |
40 end | |
41 | |
42 str = strtrim(str); | |
43 end |