Changeset 596
- Timestamp:
- 09/01/09 00:55:05 (16 years ago)
- Files:
-
- 2 added
- 3 modified
-
applications/bdmtoolbox/tutorial/estimation/mexDS_test_step.m (added)
-
applications/bdmtoolbox/tutorial/estimation/mexds_test.m (modified) (1 diff)
-
applications/bdmtoolbox/tutorial/estimation/mexds_test2.m (added)
-
library/bdm/base/bdmbase.h (modified) (2 diffs)
-
library/bdm/mex/mex_datasource.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/tutorial/estimation/mexds_test.m
r593 r596 1 y = struct('class','RV','names',{{'y'}}); 1 % function x=xxx() 2 out = struct('class','RV','names',{{'y'}}); 3 in = struct('class','RV','names',{{'u'}}); 2 4 3 5 mxD = rand(1,10); 4 5 6 %Data generating system 6 system_= struct(...7 mxADS = struct(... 7 8 'class', 'mxArrayDS',... 8 9 'varname','mxD'); 9 10 estimators = {};11 12 10 %experiment description 13 11 experiment.ndat = 9; 14 12 15 M=estimator(system_,estimators,experiment);%,logger); 13 M=estimator(mxADS,{},experiment);%,logger); 14 15 % out = mexDS_test_input + mexDS_test_input; -
library/bdm/base/bdmbase.h
r593 r596 789 789 //! Register DS for logging into logger L 790 790 virtual void log_add (logger &L) { 791 bdm_assert_debug (dtsize == Drv._dsize(), "invalid DS: dtsize different from Drv");792 bdm_assert_debug (utsize == Urv._dsize(), "invalid DS: utsize different from Urv");791 bdm_assert_debug (dtsize == Drv._dsize(), "invalid DS: dtsize ("+ num2str(dtsize)+ ") different from Drv "+ num2str(Drv._dsize())); 792 bdm_assert_debug (utsize == Urv._dsize(), "invalid DS: utsize ("+ num2str(utsize)+ ") different from Urv "+ num2str(Urv._dsize())); 793 793 794 794 L_dt = L.add (Drv, ""); … … 806 806 //!access function 807 807 virtual RV _drv() const { 808 return concat (Drv, Urv); 808 // return concat (Drv, Urv);// why!!! 809 return Drv;// why!!! 809 810 } 810 811 //!access function -
library/bdm/mex/mex_datasource.h
r593 r596 65 65 SHAREDPTR ( mxArrayDS ); 66 66 67 /*! 68 * \brief Matlab wrapper for DS mapping functions step() to a matlab function 69 70 The identifier of matlab function is stored in attribute \c name. 71 This identifier defines: 72 \li function to call to do a step(): name_step.m 73 \li workspace variable to write input to: name_input 74 */ 75 class mexDS : public DS { 76 protected: 77 //! identifier of matlab function 78 string step_name; 79 //! identifier of matlab input variabel 80 string input_name; 81 //! cache of results from name_step 82 vec dt; 83 //! cache of inputs 84 vec ut; 85 public: 86 //!Default constructor 87 mexDS ():DS() {}; 88 89 /*! \brief Create memory data source from mxArray 90 91 \code 92 system={ 93 type="mexDS"; 94 step_name=""; // name of function to call 95 input_name=""; // name of workspace variable where inputs are written 96 rv_out = {class='RV',...} // identification of outputs 97 rv_in = {class='RV',...} // identification of inputs 98 }; 99 \endcode 100 101 MemDS with the above fields will be created; 102 103 */ 104 void from_setting ( const Setting &set ) { 105 UI::get(step_name, set, "step_name", UI::compulsory); 106 UI::get(input_name, set, "input_name", UI::compulsory); 107 108 shared_ptr<RV> ry = UI::build<RV> ( set, "rv_out", UI::compulsory ); 109 shared_ptr<RV> ru = UI::build<RV> ( set, "rv_in", UI::compulsory); 110 111 dtsize=ry->_dsize(); 112 utsize=ru->_dsize(); 113 114 set_drv(*ry, *ru); 115 } 116 117 void step() { 118 mxArray* tmp; 119 mxArray* tmp2; 120 // write inputs to variable input_name 121 mxArray* mxinp= mexGetVariable ( "global", input_name.c_str()) ; 122 vec2mxArray(ut, mxinp); 123 // call function step_name 124 mexCallMATLAB(1, &tmp, 0, (mxArray **) &tmp2, step_name.c_str()); 125 // save its results 126 dt=mxArray2vec(tmp); 127 } 128 void write(vec &ut0){ ut=ut0;} 129 void getdata(vec &dt_out){dt_out = dt; } 130 131 132 // TODO dodelat void to_setting( Setting &set ) const; 133 }; 134 135 UIREGISTER ( mexDS ); 136 SHAREDPTR ( mexDS ); 137 67 138 } 68 139 #endif //MXDS_H
