SM_ADC  1.0
Приём данных АЦП через разделяемую память
matlabarray.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 //
3 // This file is part of easyLink Library.
4 //
5 // Copyright (c) 2014 FEMTO-ST, ENSMM, UFC, CNRS.
6 //
7 // License: GNU General Public License 3
8 // Author: Guillaume J. Laurent
9 //
10 //------------------------------------------------------------------------------
11 #ifndef EASYLINK_MATLABARRAY_H
12 #define EASYLINK_MATLABARRAY_H
13 
14 //------------------------------------------------------------------------------
15 #include "array.h"
16 
17 //------------------------------------------------------------------------------
18 /** \ingroup matlabArray
19  * Returns an Array connected to a MATLAB variable in a given workspace.
20  * Works only with double array.
21  * Values for workspace are: "base", "caller" or "global".
22  */
23 inline Array getMatlabArray(string name,string workspace="base")
24 {
25  const mxArray *mxarray;
26 
27  mxarray=mexGetVariablePtr(workspace.c_str(),name.c_str());
28  if (!mxarray)
29  throw runtime_error("easyLink error: Unable to find a double array named "+name+".");
30 
31  return Array(mxarray,name,true);
32 }
33 
34 //------------------------------------------------------------------------------
35 /** \ingroup matlabArray
36  * Returns true if a MATLAB variable exists with the given name in a given workspace.
37  * Works only with double array.
38  * Values for workspace are: "base", "caller" or "global".
39  */
40 inline bool existMatlabArray(string name,string workspace="base")
41 {
42  const mxArray *mxarray;
43 
44  mxarray=mexGetVariablePtr(workspace.c_str(),name.c_str());
45 
46  return (mxarray!=NULL);
47 }
48 
49 //------------------------------------------------------------------------------
50 /** \ingroup matlabArray
51  * Create a new variable in a given MATALB workspace ("base" is the
52  * default workspace) and returns an Array connected this variable.
53  * Values for workspace are: "base", "caller" or "global".
54  */
55 inline Array newMatlabArray(int nrows,int ncols,string name,string workspace="base")
56 {
57  mxArray *mxarray;
58 
59  mxarray=mxCreateDoubleMatrix(nrows,ncols, mxREAL);
60  if (!mxarray)
61  throw runtime_error("easyLink error: Unable to create a double array named "+name+".");
62 
63  if (mexPutVariable(workspace.c_str(),name.c_str(),mxarray))
64  throw runtime_error("easyLink error: Unable to put variable "+name+" in workspace "+workspace+".");
65 
66  mxDestroyArray((mxArray*)mxarray);
67 
68  return getMatlabArray(name,workspace);
69 }
70 
71 //------------------------------------------------------------------------------
72 #endif
Definition: array.h:29
Array newMatlabArray(int nrows, int ncols, string name, string workspace="base")
Definition: matlabarray.h:55
Array getMatlabArray(string name, string workspace="base")
Definition: matlabarray.h:23
bool existMatlabArray(string name, string workspace="base")
Definition: matlabarray.h:40