Mercurial > hg > ltpda
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/@unit/char.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,43 @@ +% CHAR convert a unit object into a string. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DESCRIPTION: CHAR convert a unit object into a string. +% +% CALL: string = char(unit) +% +% VERSION: $Id: char.m,v 1.11 2011/02/18 16:48:55 ingo Exp $ +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +function str = char(v) + str = ' '; + for jj=1:numel(v) + NDimensions = numel(v(jj).strs); + if NDimensions == 0 + nameString = '[]'; + else + nameString = ''; + for nd = 1:NDimensions + if(v(jj).exps(nd)~=0) + prefix = unit.val2prefix(v(jj).vals(nd)); + [n,d] = rat(v(jj).exps(nd)); + if(d==1) + if v(jj).exps(nd) ~=1 + nameString = sprintf('%s[%s%s^(%g)]', nameString,prefix,v(jj).strs{nd},v(jj).exps(nd)); + else + nameString = sprintf('%s[%s%s]',nameString,prefix,v(jj).strs{nd}); + end + else + nameString = sprintf('%s[%s%s^(%g/%g)]',nameString,prefix,v(jj).strs{nd},n,d); + end + else + nameString = sprintf('%s[]',nameString); + end + end + end + str_loop = strrep(nameString, '][', ' '); + str = [str, str_loop]; + end + + str = strtrim(str); +end