-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsfunTimesTwo.cpp
More file actions
54 lines (41 loc) · 1.38 KB
/
sfunTimesTwo.cpp
File metadata and controls
54 lines (41 loc) · 1.38 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
/*
* C++ S-function for multiplying an input by 2
*
* y = 2*u
*
* Input and output ports are dynamically sized.
*
* To compile this C++ S-function, enter the following command in MATLAB:
*
* >>make sfunTimesTwo.cpp
*
* Then open the file "testTimesTwo.mdl/slx" and start the simulation.
*/
//------------------------------------------------------------------------------
#define S_FUNCTION_NAME sfunTimesTwo
#include "EasyLink.h"
//------------------------------------------------------------------------------
class Block : public BaseBlock {
public:
static void initializeInputPortSizes() {
setInputPortsCount(1);
setInputPort(0, -1, -1, SS_DOUBLE);
}
static void initializeOutputPortSizes() {
setOutputPortsCount(1);
setOutputPort(0, -1, -1, SS_DOUBLE);
}
static void checkInputPortFinalSizes(int port, int nRows, int nCols) {
if (port == 0) {
setOutputPortFinalSizes(0, nRows, nCols);
}
}
void outputs() {
Array<double> in = getInputArray<double>(0);
Array<double> out = getOutputArray<double>(0);
out = in * 2.0;
}
};
//------------------------------------------------------------------------------
#include "sfunDefinitions.h"
//------------------------------------------------------------------------------