Author Topic: Using invoke function in Matlab  (Read 6999 times)

Offline Alex

  • Newbie
  • *
  • Posts: 5
    • View Profile
Using invoke function in Matlab
« on: July 08, 2014, 17:39:18 »
Hi,

I am using the invoke function in Matlab to handle the objects and their methods in Matlab. For example I have the following code to create a discrete labeled node:

function [ node ] = invokeDiscreteNodeLabeled(LabelCollection,domain,nodename)
%   LabelCollection is a Matlab cell containing the labels for the states
%   of the node
%   domain is the domain of the BN we consider
%   nodename is the name of the node

nstates=length(LabelCollection);
node=invoke(domain,'GetNewNode','hCategoryChance','hKindDiscrete');
set(node,'Name',nodename);
set(node,'Label',nodename);
set(node,'SubType','hSubtypeLabel');
set(node,'NumberOfStates',nstates);
for i=1:nstates
    set(node,'StateLabel',i-1,LabelCollection{i});
end

end

The above code works perfectly but when I try to do the same to create a boolean node I get the following error

Error using Interface.HUGIN_API_ActiveX_Server_7.3.Node/set
Invoke Error, Dispatch Exception:
Source: HAPI
Description: An API function was called with an invalid argument (e.g., a NULL object was passed to a
function that expects a non-NULL argument).

Error in invokeDiscreteBooleanNode (line 7)
set(node,'SubType','hSubtypeBoolean');

The code for the boolean node is the following:

function [ node ] = invokeDiscreteBooleanNode(domain,nodename)
%invokeDiscreteBooleanNode Create a boolean node

node=invoke(domain,'GetNewNode','hCategoryChance','hKindDiscrete');
set(node,'Name',nodename);
set(node,'Label',nodename);
set(node,'SubType','hSubtypeBoolean');

end

Thank you in advance for your answer !

Offline Frank Jensen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: Using invoke function in Matlab
« Reply #1 on: July 09, 2014, 19:18:27 »
You cannot set the subtype to "boolean" unless the node has exactly two states.  In other words, you must first set the number of states for the node.

Offline Alex

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Using invoke function in Matlab
« Reply #2 on: July 10, 2014, 10:48:28 »
You cannot set the subtype to "boolean" unless the node has exactly two states.  In other words, you must first set the number of states for the node.

Thank you for your reply. Adding the line

set(node,'NumberOfStates',2);

just before

set(node,'SubType','hSubtypeBoolean');

works perfectly.