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

speed improvements for itaValue

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