EasyLink
EasyLink is a C++ software development kit for developing blocks for SIMULINK (S-functions)
/Users/guillaume.laurent/Documents/Prog/easylinkEigen/easylink/sfunMatlabArrays.cpp
1 /*
2  * C++ S-function that shows all the different ways to use the matlab arrays.
3  *
4  * To compile this C++ S-function, enter the following command in MATLAB:
5  *
6  * >>make sfunMatlabArrays.cpp
7  *
8  * Then open the file "testMatlabArrays.mdl/slx" and start the simulation.
9  */
10 
11 //------------------------------------------------------------------------------
12 
13 #define S_FUNCTION_NAME sfunMatlabArrays
14 
15 #include "EasyLink.h"
16 
17 //------------------------------------------------------------------------------
18 
19 class Block : public BaseBlock {
20 private:
21 
22  Array<double> myArray;
23 
24 public:
25 
26  void start() {
27  printf("Starting the s-function for matlab array testing...\n");
28  Array<double> test = newMatlabArray(2, 2, "test");
29  test(0, 0) = 2;
30  test(1, 1) = 4;
31  myArray = test;
32  }
33 
34  void outputs() {
35  printf("---------- time = %f ----------\n", getSimulationTime());
36 
37  Array<double> test = getMatlabArray("test");
38  test += 1;
39  test.print();
40 
41  myArray += 1;
42  myArray.print();
43 
44  Array<double> a(2, 2, "A");
45  a(0, 0) = -3;
46  a(1, 1) = 4;
47  a.print();
48 
49  Array<double> b;
50  b = callMatlab<double>("inv", test);
51  b.print();
52 
53  Array<double> c = a * 3;
54  c.print();
55  }
56 
57  void terminate() {
58  printf("Terminating the s-function for matlab array testing.\n");
59  }
60 
61 };
62 
63 //------------------------------------------------------------------------------
64 
65 #include "sfunDefinitions.h"
66 
67 //------------------------------------------------------------------------------
void outputs()
Definition: BaseBlock.h:340
void print()
Definition: Array.h:318
static time_T getSimulationTime()
Definition: BaseBlock.h:704
void terminate()
Definition: BaseBlock.h:392
void start()
Definition: BaseBlock.h:327
Array< double > newMatlabArray(int nrows, int ncols, std::string name, std::string workspace="base")
Definition: MatlabArray.h:50
Array< double > getMatlabArray(std::string name, std::string workspace="base")
Definition: MatlabArray.h:22

Copyright (c) 2014 FEMTO-ST / ENSMM / UFC / UTBM, Besançon, France. Generated by Doxygen.