root/applications/bdmtoolbox/mex/merger_mx.cpp @ 384

Revision 384, 1.6 kB (checked in by mido, 15 years ago)

possibly broken?

Line 
1#include <itpp/itmex.h>
2#include <estim/merger.h>
3#include "config2mxstruct.h"
4#include "mexlog.h"
5#include "mexparse.h"
6
7using namespace bdm;
8
9void mexFunction(int n_output, mxArray *output[], int n_input, const mxArray *input[])
10{
11    // Check the number of inputs and output arguments
12        if(n_input!=1) mexErrMsgTxt("Configuration structure expected in the form:\n" 
13                "S.sources = { };                          % cell of pdfs (epdfs or mpdfs) to be merged,\n"
14                "S.merger= struct('class','merger_*');     % object to be used for merging,\n\n"
15                "see documentation of classes epdf, mpdf, merger_base and their offsprings in BDM.");
16
17        // LOAD CONFIG
18        UImxArray F (input[0]);
19
20        Array<mpdf*> Sources;
21
22        Setting& _Sources=F.lookup("sources");
23        int Slen=_Sources.getLength();
24        Sources.set_size(Slen);
25        for (int i=0; i<Slen; i++){
26                mpdf* mtmp = UI::build<mpdf>(_Sources,i);
27                if (mtmp) { 
28                        Sources(i)=mtmp;
29                } else{ // source is not mpdf
30                        epdf* etmp = UI::build<epdf>(_Sources,i);
31                        if (etmp){
32                                Sources(i) = new mepdf(etmp, true);
33                        }
34                }
35
36        }
37       
38        merger_base* Merger=UI::build<merger_base>(F.getRoot(),"merger");
39
40// COMPUTE RESULTS
41
42        Merger->merge();
43       
44        if (n_output>0){
45                mxArray* tmp = mxCreateStructMatrix(1,1,0,NULL);
46                //support
47                Array<vec> &samples=Merger->_Smp()._samples();
48                if (samples.size()>0){
49                        mxArray* fld=mxCreateDoubleMatrix(samples(0).length(), samples.size(), mxREAL);
50                Arrayvec2mxArray(samples,fld);
51                mxReplaceFieldNM(tmp, "support", fld);
52                }
53
54                //weights
55                vec &w = Merger->_Smp()._w();
56                mxArray* fldw=mxCreateDoubleMatrix(1, w.length(), mxREAL);
57                vec2mxArray(w,fldw);
58                mxReplaceFieldNM(tmp, "weights", fldw);
59               
60                output[0] = tmp;
61        }
62}
Note: See TracBrowser for help on using the browser.