forum.hugin.com

User Forums => HUGIN API Discussion => ActiveX => Topic started by: Alex on July 08, 2014, 17:39:18

Title: Using invoke function in Matlab
Post by: Alex 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 !
Title: Re: Using invoke function in Matlab
Post by: Frank Jensen 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.
Title: Re: Using invoke function in Matlab
Post by: Alex 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.