-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsfunOffset.cpp
More file actions
61 lines (45 loc) · 1.55 KB
/
sfunOffset.cpp
File metadata and controls
61 lines (45 loc) · 1.55 KB
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
/*
* This file illustrates how to construct a simple C++ S-function with
* EasyLink. The S-function has one scalar input, one scalar output and one
* scalar parameter. The output of the S-function is the sum of its input and
* of the parameter,
*
* y = u + p
*
* To compile this C++ S-function, enter the following command in MATLAB:
*
* >>make sfunOffset.cpp
*
* Then open the file "testOffset.mdl/slx" and start the simulation.
*/
//------------------------------------------------------------------------------
#define S_FUNCTION_NAME sfunOffset
#include "EasyLink.h"
//------------------------------------------------------------------------------
class Block : public BaseBlock {
public:
static void checkParametersSizes() {
assertParameterPortsCount(1);
assertParameterPort(0, true, 1, 1, mxDOUBLE_CLASS);
}
static void initializeInputPortSizes() {
setInputPortsCount(1);
setInputPort(0, 1, 1, SS_DOUBLE);
}
static void initializeOutputPortSizes() {
setOutputPortsCount(1);
setOutputPort(0, 1, 1, SS_DOUBLE);
}
void start() {
}
void outputs() {
double in = getInputDouble(0);
double offset = getParameterDouble(0);
setOutputDouble(0, in + offset);
}
void terminate() {
}
};
//------------------------------------------------------------------------------
#include "sfunDefinitions.h"
//------------------------------------------------------------------------------