1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
function sys = dataSlice(data,Start,End,Freq)
[lhs,rhs] = argn()
// storing the model data
modelData = data
// storing the statrting point
try
startData = Start
catch
startData = 1
end
//storing the end point
try
endData = End
catch
endData = LastIndex(data)
end
//Storing the frequency
try
freqData = Freq
catch
freqData = 1
end
// error message generate
if startData > endData then
error(msprintf(gettext("%s:Start index can not greater than End index.\n"),"dataSlice"))
end
if size(startData,'*') ~= 1 then
error(msprintf(gettext("%s:Start index must be non negative scalar integer number.\n"),"dataSlice"))
end
if size(endData,'*') ~= 1 then
error(msprintf(gettext("%s:End index must be non negative scalar integer number.\n"),"dataSlice"))
end
if ~freqData || size(freqData,'*') ~= 1 then
error(msprintf(gettext("%s:Frequency must be non negative scalar number.\n"),"dataSlice"))
end
//--------------------------------------------------------------------------
if typeof(modelData) == 'constant' then
Ts = 1
elseif typeof(modelData) == 'iddata' then
Ts = modelData.Ts
end
//--------------------------------------------------------------------------
if freqData> Ts || modulo(Ts,freqData) then
warning(msprintf(gettext("%s:inconsistent frequency.\n"),"dataSlice"))
freqData = Ts
end
if typeof(modelData) == 'constant' then
temp = modelData(startData:Ts/freqData:endData,:)
elseif typeof(modelData) == 'iddata' then
tempY = modelData.OutputData;tempU = modelData.InputData
tempY = tempY(startData:Ts/freqData:endData,:);tempU = tempU(startData:Ts/freqData:endData,:)
temp = iddata(tempY,tempU,Ts/freqData)
temp.TimeUnit = modelData.TimeUnit
end
sys = temp
endfunction
function varargout = LastIndex(modelData)
//finding the sample size
if typeof(modelData) == "constant" then
varargout(1) = length(modelData(:,1))
elseif typeof(modelData) == "iddata" then
temp = modelData.OutputData
varargout(1) = length(temp(:,1))
end
endfunction
|