setSignalName.m 2.35 KB
Newer Older
1
function myStateSpace = setSignalName(myStateSpace, signalType, signalNames, signalLength)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
% SETSSSIGNALNAME sets the property 'OutputName' or 'InputName' of the ss 
% myStateSpace to signalNames. Therein, signalLength how many output elements belong 
% to a signalName. Wheather the InputName or the OutputName properties should be set
% is determined by signalType \in {'input', 'output'}
%
% Inputs:
%	myStateSpace	state space whoms OutputName should be modified
%	signalType		must be either 'input' or 'output' and determines of OutputName
%					or InputName are set
%	signalNames		cell array of signal names that should be applied to
%					myStateSpace.OutputName
%	signalLength	cell array of same size as signal names. Each element defines the
%					length of the signal that is named in signal names
% Outputs:
%	myStateSpace	the state space with modified parameters
%
% Example:
% -------------------------------------------------------------------------
% 	mySimulationModel = ss(1, 1, [1; 2; 3], []);
21
%	mySimulationModel = misc.ss.setSignalName(mySimulationModel, "output", ["a", "b"], [2, 1]);
22
23
% -------------------------------------------------------------------------

24
25
26
27
28
arguments
	myStateSpace ss;
	signalType (1, 1) string;
	signalNames (:, 1) string;
	signalLength (:, 1) double;
29
end
30

31
% input checks
32
if strcmp(signalType, "input")
33
	assert(size(myStateSpace, 2) == sum(signalLength), "signalLength does not fit to state space");
34
elseif strcmp(signalType, "output")
35
	assert(size(myStateSpace, 1) == sum(signalLength), "signalLength does not fit to state space");
36
37
38
else
	error("signalType must be 'input' or 'output'");
end
39
assert(numel(signalNames) == numel(signalLength), "signalNames must have same number as signalLength");
40

41
42
43
44
45
46
47
48
49
50
51
52
53
signalNames = signalNames(signalLength>0);
signalLength = signalLength(signalLength>0);
% create name names
myNewSignalNames = signalNames(1);
if signalLength(1) > 1
	myNewSignalNames = myNewSignalNames + "(" + string((1:1:signalLength(1)).') + ")";
end
for it = 2 : numel(signalNames)
	if signalLength(it) > 1
		myNewSignalNames = [myNewSignalNames; ...
			signalNames(it) + "(" + string((1:1:signalLength(it)).') + ")"];
	else
		myNewSignalNames = [myNewSignalNames; signalNames(it)];
54
55
56
57
	end
end

% set property
58
if strcmp(signalType, "input")
59
60
61
62
	myStateSpace.InputName = myNewSignalNames;
else
	myStateSpace.OutputName = myNewSignalNames;
end
63
end % misc.ss.setSignalName()