Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LRT_infinite_dimensional_systems
conI
Commits
4ec292a2
Commit
4ec292a2
authored
Dec 02, 2019
by
Ferdinand Fischer
Browse files
close
#6
: Implemented a sort function to sort the grids before the concatenation
parent
2abce96a
Changes
2
Hide whitespace changes
Inline
Side-by-side
+quantity/Discrete.m
View file @
4ec292a2
...
...
@@ -427,7 +427,44 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
end
end
end
% gridJoin()
function
obj
=
sort
(
obj
,
varargin
)
%SORT sorts the grid of the object in a desired order
% obj = sortGrid(obj) sorts the grid in alphabetical order.
% obj = sort(obj, 'descend') sorts the grid in descending
% alphabetical order.
if
nargin
==
2
&&
strcmp
(
varargin
{
1
},
'descend'
)
descend
=
1
;
else
descend
=
0
;
end
% only sort the grids if there is something to sort
if
obj
(
1
)
.
nargin
>
1
gridNames
=
obj
(
1
)
.
gridName
;
% this is the default case for ascending alphabetical
% order
[
sortedNames
,
I
]
=
sort
(
gridNames
);
% if descending: flip the order of the entries
if
descend
sortedNames
=
flip
(
sortedNames
);
I
=
flip
(
I
);
end
% sort the grid entries
[
obj
.
grid
]
=
deal
(
obj
(
1
)
.
grid
(
I
));
% assign the new grid names
[
obj
.
gridName
]
=
deal
(
sortedNames
);
% permute the value discrete
for
k
=
1
:
numel
(
obj
)
obj
(
k
)
.
valueDiscrete
=
permute
(
obj
(
k
)
.
valueDiscrete
,
I
);
end
end
end
% sort()
function
c
=
horzcat
(
a
,
varargin
)
%HORZCAT Horizontal concatenation.
% [A B] is the horizontal concatenation of objects A and B
...
...
@@ -520,7 +557,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% this function has the very special thing that it a does
% not have to be an quantity.Discrete object. So it has to
% be checked which of the input arguments is an
% quantity.Discrete object. This is considered to
be
give
% quantity.Discrete object. This is considered to give
% the basic values for the initialization of new
% quantity.Discrete values
isAquantityDiscrete
=
cellfun
(
@
(
o
)
isa
(
o
,
'quantity.Discrete'
),
objCell
);
...
...
@@ -568,10 +605,14 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
end
% sort the grid names of each quantity
for
it
=
1
:
(
numel
(
varargin
)
+
1
)
objCell
{
it
}
=
objCell
{
it
}
.
sort
;
end
[
fineGrid
,
fineGridName
]
=
getFinestGrid
(
objCell
{
~
isEmpty
});
for
it
=
1
:
(
numel
(
varargin
)
+
1
)
% +1 because the first entry is a
assert
(
all
(
strcmp
(
fineGridName
,
objCell
{
it
}(
1
)
.
gridName
)),
...
'gridNames of objects that are concatenated must be equal'
);
% change the grid to the finest
objCell
{
it
}
=
objCell
{
it
}
.
changeGrid
(
fineGrid
,
fineGridName
);
end
assertSameGrid
(
objCell
{:});
...
...
+unittests/+quantity/testDiscrete.m
View file @
4ec292a2
...
...
@@ -155,7 +155,7 @@ end
function
testConcatenate
(
testCase
)
t
=
linspace
(
0
,
pi
)
'
;
t
=
linspace
(
0
,
pi
,
7
)
'
;
A
=
quantity
.
Discrete
({
sin
(
t
);
cos
(
t
)},
'grid'
,
{
t
},
'gridName'
,
't'
);
B
=
quantity
.
Discrete
({
tan
(
t
);
exp
(
t
)},
'grid'
,
{
t
},
'gridName'
,
't'
);
...
...
@@ -183,6 +183,18 @@ O_vert = [O; O];
testCase
.
verifyEqual
(
size
(
O_horz
,
1
),
5
);
testCase
.
verifyEqual
(
size
(
O_vert
,
1
),
10
);
z
=
linspace
(
0
,
1
,
5
);
D
=
quantity
.
Discrete
({
sin
(
t
*
z
);
cos
(
t
*
z
)},
'grid'
,
{
t
,
z
},
'gridName'
,
{
't'
,
'z'
});
E
=
quantity
.
Discrete
({
tan
(
z
' * t'
);
cos
(
z
' * t'
)},
'grid'
,
{
z
,
t
},
'gridName'
,
{
'z'
,
't'
});
DE
=
[
D
,
E
];
compareDE
=
quantity
.
Discrete
({
sin
(
t
*
z
),
tan
(
t
*
z
);
cos
(
t
*
z
),
cos
(
t
*
z
)},
'grid'
,
{
t
,
z
},
'gridName'
,
{
't'
,
'z'
});
testCase
.
verifyEqual
(
DE
.
on
(),
compareDE
.
on
())
ED
=
[
E
,
D
];
compareED
=
quantity
.
Discrete
({
tan
(
t
*
z
),
sin
(
t
*
z
);
cos
(
t
*
z
),
cos
(
t
*
z
)},
'grid'
,
{
t
,
z
},
'gridName'
,
{
't'
,
'z'
});
testCase
.
verifyEqual
(
ED
.
on
(),
compareED
.
on
())
end
function
testExp
(
testCase
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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