Spark! Fuzzy Logic Editor Help


Variables | Sets | Rules | API | Integration | Tutorial


set_value()

Sets the value of an input fuzzy variable.

int set_value(int var_idx, float value)

Parameters

int var_idx index of the variable to get the value for
float value Value to set the variable to

Return Value

0 - Successfully set the value
non-zero - Unable to set value, get error text via get_msg_textA().  

Remarks

You are only allowed to set the value for input variables.  Output variables have their value calculated dependent on the rules and input variable values.

If you try to set a value outside the range of the variable, the variable's value is set to the closest either the min or max value (whichever is closest to the value passed in).

The index of the variable should be from the .h file exported from the Spark! model.  The variable's  index may not coincide with the screen position of the variable.

See Export .h File for more information

Example

void set_values(SparkModel* model)
{
    float value;

    cout << "Enter value for Variable 1: ";
    cin >> value;

    // set the value...
    model->set_value(FUZZY_VAR_1_IDX, value);

} // end set_values()