view m-toolbox/classes/@unit/char.m @ 16:91f21a0aab35 database-connection-manager

Update utils.jquery * * * Update utils.jmysql.getsinfo
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

% 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