Defining a trained classifier as a global variable in Matlab

Working with OpenViBE signal processing scenarios and doing scenario/BCI design
Post Reply
eli.young
Posts: 2
Joined: Wed Nov 22, 2017 6:42 pm

Defining a trained classifier as a global variable in Matlab

Post by eli.young »

Hello! I have an already trained classifier and a I need to load it only once, when pressing play to the scenario. I'm using a Matlab Scripting Box, and I want to know if it should be loaded in the "Initialize" script of the box and declared as global (an how to use it after that) or if I should do it in the "Process" script.

Thank you! :D

jtlindgren
Posts: 778
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: Defining a trained classifier as a global variable in Ma

Post by jtlindgren »

Hello Eli,

global variables can get a bit messy, so I recommend doing it like this,

Code: Select all

       % in initialize.m
       box_in.user_data.classifier = myClassifier; % store your loaded classifier
       box_out = box_in;  % pass it out to openvibe

       % in process.m
       myClassifier = box_in.user_data.classifier;  % take the classifier from openvibe
       % use it somehow

For reference, the global variable solution would look like

Code: Select all

     % in initialize.m
     global myClassifier;
     % do something to initialize it, load from disk or whatever

     % in process.m
     global myClassifier;
     % use it somehow
In any case, if you have a premade classifier, you should definitely load/build it in initialize unless you have some reason to do it in process.


Hope this helps,
Jussi

eli.young
Posts: 2
Joined: Wed Nov 22, 2017 6:42 pm

Re: Defining a trained classifier as a global variable in Ma

Post by eli.young »

jtlindgren wrote:Hello Eli,

global variables can get a bit messy, so I recommend doing it like this,

Code: Select all

       % in initialize.m
       box_in.user_data.classifier = myClassifier; % store your loaded classifier
       box_out = box_in;  % pass it out to openvibe

       % in process.m
       myClassifier = box_in.user_data.classifier;  % take the classifier from openvibe
       % use it somehow

For reference, the global variable solution would look like

Code: Select all

     % in initialize.m
     global myClassifier;
     % do something to initialize it, load from disk or whatever

     % in process.m
     global myClassifier;
     % use it somehow
In any case, if you have a premade classifier, you should definitely load/build it in initialize unless you have some reason to do it in process.


Hope this helps,
Jussi
Thank you! It helps a lot!! :D :D

Post Reply