Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Institute of Technical Acoustics (ITA)
toolbox
Commits
0e753a93
Commit
0e753a93
authored
Dec 12, 2016
by
Marco Berzborn
Browse files
speed improvements for itaValue
parent
ec28dbd8
Changes
2
Hide whitespace changes
Inline
Side-by-side
kernel/ClassStuff/@itaValue/itaValue.m
View file @
0e753a93
...
...
@@ -39,8 +39,8 @@ classdef itaValue
elseif
ischar
(
varargin
{
1
})
token
=
varargin
{
1
}(:)
.'
;
if
~
is
empty
(
str2num
(
token
))
%pre check if only a value inside, pdi
A
.
value
=
str2
num
(
token
);
if
~
is
nan
(
str2double
(
token
))
%pre check if only a value inside, pdi
A
.
value
=
str2
double
(
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
=
s
tr2num
(
value_token
);
%#ok<ST2NM>
A
.
value
=
s
scanf
(
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'
))
&&
s
tr2num
(
x
.
Version
)
<
7.13
% check if we are in desktop mode
if
isempty
(
javachk
(
'desktop'
))
&&
s
scanf
(
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,13 +278,13 @@ 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
end
end
\ No newline at end of file
end
kernel/MetaInfo/ita_deal_units.m
View file @
0e753a93
...
...
@@ -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
=
find
str
(
unitStr
,
' '
);
tokenPos
=
str
find
(
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
=
s
tr2num
(
token
(
isstrprop
(
token
,
'digit'
)));
exponent
=
s
scanf
(
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
(
find
str
(
numStr
,
' '
)
)
%#ok<*REMFF1> %more than one token
if
~
isempty
(
str
find
(
numStr
,
' '
))
%#ok<*REMFF1> %more than one token
numStr
=
[
'('
numStr
')'
];
end
if
~
isempty
(
find
str
(
denStr
,
' '
)
)
%more than one token
if
~
isempty
(
str
find
(
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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment