Debian Codegraph @

texmf-dist/doc/latex/numericplots/src/MatlabSupport.tex

raw
1
2 \section{Matlab Support}
3
4
5 \subsection{export2latex.m}
6 The function \texttt{export2latex(data, filename, [options])} may be used to
7 export data from Matlab to be used with NumericPlots.sty. The function takes the
8 two parameters data and filename, where filename is the name of the file where
9 the data should be stored with full path but without extension. Data is a
10 structure with the three entries x, y, and ident, where x are the x-data, y the
11 y-data and ident is an identifier to have access to the data in Latex. To access
12 the data in Latex the command \verb+\Data<ident>+ is used.
13
14 The parameter data may be provided as an 1xK array if each entry of the array is
15 a structure with the entries x, y and ident. There may be an additional entry
16 descr.
17 \begin{itemize}
18 \item data(1,i).x = $X_i$
19 \item data(1,i).y = $Y_i$
20 \item data(1,i).ident = Identifier
21 \item (data(1,i).descr = Description)
22 \item (data(1,i).group = GroupNr)
23 \end{itemize}
24 Identifier must be a valid Latex command name, which basically means it must be
25 a string without numbers.
26
27 For every entry of data, $X$ and $Y$ must be arrays of the same size
28 $M\text{x}N$. If $M>1$, each column of the array is exported to the file and the
29 identifier is expanded by the roman representation of the column number.
30
31 It might be useful to do a \texttt{interp1} before exporting the data to get
32 smaller files and to use less of \TeX's memory. ($\rightarrow$ script
33 Patrick?!?)
34
35 The optional parameter \texttt{options} might be used to control which
36 additional information is provided in the output file.
37 \begin{itemize}
38 \item \texttt{options.DataBoundaries} [true] If set to true, the output file
39 contains the commands \verb+\DataXmin+, \verb+\DataXmax+, \verb+\DataYmin+ and
40 \verb+\DataYmax+ which may be used to define the axis.
41 \item \texttt{options.AxisBoundaries} [false] If set to true, the output file
42 contains the commands \verb+\DataXminAxis+, \verb+\DataXmaxAxis+,
43 \verb+\DataYminAxis+ and \verb+\DataYmaxAxis+ which may be used to define the
44 axis. In contrary to the DataBoundaries the AxisBoundaries add an additional
45 gap of \texttt{options.AxisBoundariesGap} [10] percent of the full scale to
46 the data boundaries such that the plot doesn't touch the axis.
47 \item \texttt{options.SuppressWarning} [false] suppresses the warning about
48 max/min values being to close together
49 \item \texttt{options.precision} [empty] how many decimal places should be
50 printed for x and y values. Will be calculated automatically if left empty.
51 \item \texttt{options.NaNsplit [false]} if true, the data will be split at NaN
52 values. See \verb+\multilistplot+ for how to plot them.
53 \end{itemize}
54
55 \subsection{struct2latex.m}
56 The function\\
57 \texttt{struct2latex(data,[xname],[downsample],[filtertype],[filename],[postfix],[options])}\\
58 may be used to export a Matlab struct to be used with NumericPlots.sty. The
59 function is based on export2latex and the \verb+options+ argument is given to
60 export2latex. The optional argument \verb+xname+ specifies the fieldname of the
61 x-data. If no \verb+xname+ is given, you have to chose one via popup. All other
62 fields are treated like y-data. Furthermore, the identifier of the y-data are
63 equal to the fieldnames and have to be valid Latex commands (fieldnames with
64 numbers are not supported). The struct2latex command only supports 1 dimensional
65 arrays (row vectors). Column vectors are mapped for propper export without
66 warning. With the optional argument \verb+downsample+ (integer$>0$) it is
67 possible to downsample the data for smaller files. A warning is given when data
68 points exceed $5000$. Usually $1000$ data points are enough for a propper plot
69 in latex. The optional argument \verb+filename+ specifies the outputname with
70 path of the texfile. If no filename is given, it has to be chosen via popup. The
71 optional argument \verb+postfix+ can be used to put a postfix after the
72 fieldname in the identifier of the y-data. The \verb+options+ argument is also
73 optional and equal to the options argument of the function export2latex.
74
75 Filter may be one of \verb+{'none','MinMax','Hull'}+. The corresponding
76 filter will be applied to the data before exporting it. See
77 \ref{sec:FurtherExamples:NoisyData} for further details.
78
79 Matlab example.
80 \begin{verbatim}
81 % data for struct2latex should be row-vectors. anyway, column-vectors are
82 % mapped to row-vectors. matrices are not supported
83
84 %% export row-vectors
85 t = [1:0.1:10];
86
87 data.time = t;
88 data.sin = sin(t);
89 data.cos = cos(t);
90 data.exp = exp(t);
91 data.tan = tan(t);
92
93 %struct2latex(data,xname,downsample,filename,filtertype,postfix,options)
94 %downsample,filename,postfix,options are optional arguments
95 struct2latex(data,'time',1,'none','texdataA','row');
96 \end{verbatim}
97
98 \subsection{dspace2struct}
99 The function \texttt{dspace2struct(dataname,version)} may be used to import
100 \texttt{.mat} created by \textsc{dSpace} to \textsc{Matlab}. It returns a
101 \textsc{Matlab} struct out of the provided variables \verb+dataname+ and
102 \verb+version+. Thereby \verb+dataname+ is the name of the \textsc{dSpace}
103 \verb+.mat+ file and the optional string argument \verb+version+ has to be equal
104 \verb+version = 'NG'+ if \textsc{dSpace Control Desk Next Generation} is used.
105 It is convenient to chose a unique signal name in \textsc{Matlab/Simulink}
106 because they will be the same in \textsc{dSpace}. The function
107 \texttt{dspace2struct(dataname,version)} just adopts the names provided by
108 \textsc{dSpace} and use them as fieldnames. The time vector will always be
109 called \verb+.time+.
110
111 Matlab example:
112 \begin{verbatim}
113 % Old Control Desk:
114 dataOG = dspace2struct(measurements)
115 % Control Desk Next Generation:
116 dataNG = dspace2struct(measurements,'NG')
117 \end{verbatim}
118
119 The resulting structs \verb+dataOG+ and \verb+dataNG+ differ in way of
120 structuring. In the older versions of \textsc{dSpace} it was only possible to
121 save one time vector. The \textsc{dSpace Control Desk Next Generation} allows to
122 save several time vectors. So it was necessary to save the index of the time
123 vector with the signal name. Typical plot commands for the two data structures
124 look as follows:
125 \begin{verbatim}
126 %Old Control Desk
127 plot(dataOG.time,dataOG.signalname);
128
129 %Control Desk Next Generation
130 plot(dataNG.time(dataNG.signalname.timeidx),dataNG.signalname.Data);
131 \end{verbatim}
132 \subsection{dspace2latex}
133 The function \texttt{dspace2latex} is just a combination of
134 \texttt{dspace2struct} and \texttt{struct2latex} with commonly used arguments.
135 It is a simple and quick way to export measurements from \textsc{dSpace} to
136 \LaTeX{} without any revision of the data. However, the current implementation
137 allows only data structures of the old version of \textsc{dSpace Control Desk}.