Commit fdb18963 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

misc.ss.*: made more robust wrt strings or ss without inputs

parent a82544f8
......@@ -14,7 +14,9 @@ function myStateSpaceNew = addState2output(myStateSpace, stateName)
% 'OutputName', {'y', 'z'}, 'InputName', {'u(1)', 'u(2)', 'a'});
% mySimulationModel = misc.ss.addState2output(mySimulationModel, 'x');
% -------------------------------------------------------------------------
if isstring(stateName)
stateName = char(stateName);
end
newC = vertcat(myStateSpace.C, eye(size(myStateSpace.A)));
newD = vertcat(myStateSpace.D, zeros(size(myStateSpace.A, 1), size(myStateSpace, 2)));
stateNameList = repmat({stateName}, size(myStateSpace.A, 1), 1);
......@@ -23,7 +25,7 @@ for it = 1 : numel(stateNameList)
end
newOutputName = [myStateSpace.OutputName; stateNameList];
myStateSpaceNew = ss(myStateSpace.A, myStateSpace.B, newC, newD, myStateSpace.Ts, ...
'InputName', myStateSpace.InputName, ...
'OutputName', newOutputName);
"InputName", myStateSpace.InputName, ...
"OutputName", newOutputName);
end
\ No newline at end of file
......@@ -26,10 +26,19 @@ for it = 1 : numel(inputSs)
inputSs{it}.InputName = misc.ss.removeSingularEnumeration(inputSs{it}.InputName);
end
% get InputNames of result
resultInputNames = unique(misc.ss.removeSingularEnumeration(InputName), 'stable');
resultOutputNames = unique(misc.ss.removeSingularEnumeration(OutputName), 'stable');
if isempty(resultInputNames)
% as ss/connect does not support empty cell array for inputNames or outputNames, this dummy
% object is added for those cases.
resultInputNames = {"dummy.input"};
resultOutputNames = [resultOutputNames; "dummy.output"];
inputSs = [inputSs, ...
{ss([], [], [], 0, "InputName", {"dummy.input"}, "OutputName", {"dummy.output"})}];
end
% call built-in function
resultSs = connect(inputSs{:}, ...
unique(misc.ss.removeSingularEnumeration(InputName), 'stable'), ...
unique(misc.ss.removeSingularEnumeration(OutputName), 'stable'), ...
options);
resultSs = connect(inputSs{:}, resultInputNames, resultOutputNames, options);
end
\ No newline at end of file
......@@ -22,21 +22,21 @@ function myStateSpace = setSignalName(myStateSpace, signalType, signalNames, sig
% -------------------------------------------------------------------------
% input checks
assert(isa(myStateSpace, 'ss'), '1st input must be state space model');
assert(iscell(signalNames), 'signalNames must be a cell array');
assert(iscell(signalLength) || isvector(signalLength), 'signalLength must be a cell array or a vector');
assert(isa(myStateSpace, "ss"), "1st input must be state space model");
assert(iscell(signalNames), "signalNames must be a cell array");
assert(iscell(signalLength) || isvector(signalLength), "signalLength must be a cell array or a vector");
if iscell(signalLength)
signalLength = cell2mat(signalLength);
end
if strcmp(signalType, 'input')
assert(size(myStateSpace, 2) == sum([signalLength(:)]), 'signalLength does not fit to state space');
elseif strcmp(signalType, 'output')
assert(size(myStateSpace, 1) == sum([signalLength(:)]), 'signalLength does not fit to state space');
if strcmp(signalType, "input")
assert(size(myStateSpace, 2) == sum([signalLength(:)]), "signalLength does not fit to state space");
elseif strcmp(signalType, "output")
assert(size(myStateSpace, 1) == sum([signalLength(:)]), "signalLength does not fit to state space");
else
error("signalType must be 'input' or 'output'");
end
assert(numel(signalNames) == numel(signalLength), 'signalNames must have same number as signalLength');
assert(numel(signalNames) == numel(signalLength), "signalNames must have same number as signalLength");
% create name cell array
myNewSignalNames = cell(sum([signalLength(:)]), 1);
......@@ -44,16 +44,16 @@ myCurrentSignal = 1;
for it = 1 : numel(signalNames)
for jt = 1 : signalLength(it)
if signalLength(it) == 1
myNewSignalNames{myCurrentSignal} = signalNames{it};
myNewSignalNames{myCurrentSignal} = char(signalNames{it});
else
myNewSignalNames{myCurrentSignal} = [signalNames{it}, '(', num2str(jt), ')'];
myNewSignalNames{myCurrentSignal} = [char(signalNames{it}), '(', num2str(jt), ')'];
end
myCurrentSignal = myCurrentSignal + 1;
end
end
% set property
if strcmp(signalType, 'input')
if strcmp(signalType, "input")
myStateSpace.InputName = myNewSignalNames;
else
myStateSpace.OutputName = myNewSignalNames;
......
Supports Markdown
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