Commit 0e753a93 authored by Marco Berzborn's avatar Marco Berzborn

speed improvements for itaValue

parent ec28dbd8
......@@ -39,8 +39,8 @@ classdef itaValue
elseif ischar(varargin{1})
token = varargin{1}(:).';
if ~isempty(str2num(token)) %pre check if only a value inside, pdi
A.value = str2num(token);
if ~isnan(str2double(token)) %pre check if only a value inside, pdi
A.value = str2double(token);
else
%token_new = token; token_new(token_new == '.') = ' ';
unit_start = find(isstrprop(token,'alpha'));
......@@ -59,10 +59,12 @@ classdef itaValue
else
unit_start = unit_start(1);
end
catch
% do nothing
end
value_token = token(1:unit_start-1);
value_token = value_token(value_token ~= ' ');
A.value = str2num(value_token); %#ok<ST2NM>
A.value = sscanf(value_token,'%f');
if isempty(A.value)
A.value = 1;
end
......@@ -95,7 +97,7 @@ classdef itaValue
if length(a) > 1
res = [];
for idx = 1:length(a)
res = [res ' ' num2str(a(idx),varargin{:})];
res = [res ' ' num2str(a(idx),varargin{:})]; %#ok<AGROW>
end
else
res = num2str(a.value(:),varargin{:});
......@@ -145,7 +147,7 @@ classdef itaValue
% invert a matrix
res = ita_unit_inv(a);
values = inv(double(a));
for idx = 1:size(a,1);
for idx = 1:size(a,1)
for jdx = 1:size(a,2)
res(idx,jdx).value = values(idx,jdx);
end
......@@ -189,23 +191,13 @@ classdef itaValue
%% disp
function disp(a)
% show the variable value and string
% spacing = 10;
% for idx = 1:size(a,1)
% aux = '';
% for jdx = 1:size(a,2)
% newString = num2str(a(idx,jdx));
% aux = [newString repmat('',1,spacing - length(newString))];
% end
% disp(aux)
% end
disp(num2str(a))
end
function display(a)
function display(a) %#ok<DISPLAY>
% show the variable value and string
x = ver('matlab');
if isempty(javachk('desktop')) && str2num(x.Version) < 7.13 % check if we are in desktop mode
if isempty(javachk('desktop')) && sscanf(x.Version,'%f') < 7.13 % check if we are in desktop mode
spacing = 15;
if size(a,1) == 1 && size(a,2) == 1 %normal 1D disp
......@@ -286,10 +278,10 @@ classdef itaValue
end
varargout{1} = res; %return string for e.g. legend
if nargout >= 2;
if nargout >= 2
varargout{2} = val; %return double for division
end
if nargout >= 3;
if nargout >= 3
varargout{3} = log_prefix; %scaling factor for log10
end
end
......
......@@ -158,8 +158,8 @@ end
end
end
[num1 den1] = unitstr2nums(numToken);
[den2 num2] = unitstr2nums(denToken);
[num1, den1] = unitstr2nums(numToken);
[den2, num2] = unitstr2nums(denToken);
num = num1 * num2;
den = den1 * den2;
......@@ -169,7 +169,7 @@ end
return;
end
unitStr(unitStr == '*') = ' ';
tokenPos = findstr(unitStr,' ');
tokenPos = strfind(unitStr,' ');
tokenPos = [1 tokenPos length(unitStr)];
num = 1; den = 1; %init
......@@ -192,7 +192,7 @@ end
end
exponent = 1;
if any(isstrprop(token,'digit'))
exponent = str2num(token(isstrprop(token,'digit')));
exponent = sscanf(token(isstrprop(token,'digit')),'%f');
token = token(~isstrprop(token,'digit'));
end
......@@ -253,7 +253,6 @@ end
den = den * cc.tesla(2).^exponent;
case 'rad'
num = num * cc.rad.^exponent;
den = den;
otherwise
if ~isempty(token)
ita_verbose_info(['Oh Lord. I do not know this unit: ' token '! Ignoring this...'])
......@@ -355,10 +354,10 @@ end
end
%% more than one element?
if ~isempty( findstr(numStr,' ') ) %#ok<*REMFF1> %more than one token
if ~isempty(strfind(numStr,' ')) %#ok<*REMFF1> %more than one token
numStr = ['(' numStr ')'];
end
if ~isempty( findstr(denStr,' ') ) %more than one token
if ~isempty(strfind(denStr,' ')) %more than one token
denStr = ['(' denStr ')'];
end
if isempty(numStr) && isempty(denStr)
......@@ -694,7 +693,7 @@ end
for i = maxExponent:-1:1
if isfactor(numFactor.^i,iNum) && isfactor(denFactor.^i,iDen)
if i ~= 1
newString = [newString '^' num2str(i)]; %#ok<AGROW>
newString = [newString '^' num2str(i)];
end
iNum = iNum/numFactor.^i;
iDen = iDen/denFactor.^i;
......@@ -831,7 +830,7 @@ end
function [iNum, iDen, numString] = check4hertz(iNum,iDen,numString)
numFactor = 1; denFactor = cc.second; newString = 'Hz'; %hertz
if iDen == denFactor && iNum == numFactor;
if iDen == denFactor && iNum == numFactor
iNum = iNum/numFactor;
iDen = iDen/denFactor;
numString = appendString(numString,newString);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment