1 | #include "stat/loggers.h" |
---|
2 | |
---|
3 | namespace bdm{ |
---|
4 | int mxReplaceFieldNM(mxArray *X,const char * fname,mxArray *X1) |
---|
5 | { |
---|
6 | mxArray *Old; |
---|
7 | int i; |
---|
8 | |
---|
9 | if((i=mxGetFieldNumber(X,fname))==-1) |
---|
10 | { |
---|
11 | if((i=mxAddField(X,fname))==-1) return i; |
---|
12 | |
---|
13 | } |
---|
14 | |
---|
15 | Old=mxGetFieldByNumber(X,0,i); |
---|
16 | if(Old)mxDestroyArray(Old); |
---|
17 | mxSetFieldByNumber(X,0,i,X1); |
---|
18 | return i; |
---|
19 | |
---|
20 | }; |
---|
21 | |
---|
22 | class mexlog : public memlog { |
---|
23 | public: |
---|
24 | //! constructor |
---|
25 | mexlog(): memlog(0,"mx"){}; |
---|
26 | //! |
---|
27 | mxArray* toCell(){ |
---|
28 | mxArray* tmp = mxCreateStructMatrix(1,1,0,NULL); |
---|
29 | |
---|
30 | //copied from itsave |
---|
31 | int i; |
---|
32 | string vec_name=""; |
---|
33 | int istart, iend; |
---|
34 | |
---|
35 | mat M; //temporary matrix |
---|
36 | for ( i=0; i<entries.length();i++ ) { |
---|
37 | istart=0; |
---|
38 | for (int j=0; j<entries(i).length(); j++){ // same for as in add!!! |
---|
39 | vec_name = names(i) + entries(i).name(j); |
---|
40 | iend=istart+entries(i).size(j)-1; |
---|
41 | M=vectors(i).get_cols(istart,iend); |
---|
42 | istart=iend+1; |
---|
43 | // copy the selection to mx |
---|
44 | mxArray* fld=mxCreateDoubleMatrix(M.rows(), M.cols(), mxREAL); |
---|
45 | mat2mxArray(M,fld); |
---|
46 | mxReplaceFieldNM(tmp, vec_name.c_str(), fld); |
---|
47 | } |
---|
48 | } |
---|
49 | return tmp; |
---|
50 | } |
---|
51 | void from_setting (const Setting &root){ |
---|
52 | maxlen=root["maxlen"]; |
---|
53 | } |
---|
54 | }; |
---|
55 | UIREGISTER(mexlog); |
---|
56 | } |
---|