Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.3.2 - English

Change language to:
Français - 日本語 - Português

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
However, this page did not exist in the previous stable version.

Scilab help >> API Scilab > boolean > boolean example

boolean example

Boolean use case.

Description

This example shows how to get a boolean variable and return it to Scilab.

Gateway Source

int booleanExample(char *fname,unsigned long fname_len)
{
    SciErr sciErr;
    int* piAddr = NULL;
    int iType   = 0;
    int iRet    = 0;

    CheckRhs(1,1);
    CheckLhs(0,1);

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    if(isBooleanType(pvApiCtx, piAddr))
    {
        if(isScalar(pvApiCtx, piAddr))
        {
            int iBool = 0;
            iRet = getScalarBoolean(pvApiCtx, piAddr, &iBool);
            if(iRet)
            {
                return 0;
            }

            iRet = createScalarBoolean(pvApiCtx, Rhs + 1, iBool);
            if(iRet)
            {
                return 0;
            }
        }
        else
        {
        int iRows	= 0;
        int iCols	= 0;
        int *piBool	= NULL;

        sciErr = getMatrixOfBoolean(pvApiCtx, piAddr, &iRows, &iCols, &piBool);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 1, iRows, iCols, piBool);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
    }
        LhsVar(1) = Rhs + 1;
    }
    else
    {
        LhsVar(1) = 0;
    }
    return 0;
}

Scilab test script

a = %t;
b = %f;
c = [a,b;b,a;a,b;b,a];
d = c';

booleanExample(a) == a
booleanExample(b) == b
booleanExample(c) == c
booleanExample(d) == d
<< createScalarBoolean boolean Boolean Sparse >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu May 12 11:44:29 CEST 2011