Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - Français

Change language to:
English - 日本語 - 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.

Aide de Scilab >> API Scilab > legacy > Low level functions > Check variable dimensions (Scilab gateway)

Check variable dimensions (Scilab gateway)

A C gateway functions which check dimensions of a variable.

Syntax

int checkVarDimension(void* _pvCtx, int* _piAddress, int _iRows, int _iCols)
int isRowVector(void* _pvCtx, int* _piAddress)
int isColumnVector(void* _pvCtx, int* _piAddress)
int isVector(void* _pvCtx, int* _piAddress)
int isScalar(void* _pvCtx, int* _piAddress)
int isSquareMatrix(void* _pvCtx, int* _piAddress)
int isEmptyMatrix(void* _pvCtx, int* _piAddress)

Arguments

_pvCtx

Scilab environment pointer, pass in "pvApiCtx" provided by api_scilab.h

_piAddress

Address of the Scilab variable.

_iRows

Expected row count

_iCols

Expected col count

Description

A C gateway functions which check dimensions of a variable.

Examples

In this example, the C interface function can take several input arguments and prints input dimensions and several test results.

#include "api_scilab.h"
#include "sciprint.h"

int check_matrix_dimension(char * fname)
{
    SciErr sciErr;
    int* piAddr = NULL;
    int iRows = 0;
    int iCols = 0;

    CheckInputArgument(pvApiCtx, 1, 1);

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

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

    if(checkVarDimension(pvApiCtx, piAddr, iCols, iRows))
    {
        sciprint("checkVarDimension returns false\n");
    }
    else
    {
        sciprint("checkVarDimension returns true\n");
    }

    if(isRowVector(pvApiCtx, piAddr))
    {
        sciprint("isRowVector\n");
    }

    if(isColumnVector(pvApiCtx, piAddr))
    {
        sciprint("isColumnVector\n");
    }

    if(isVector(pvApiCtx, piAddr))
    {
        sciprint("isVector\n");
    }

    if(isScalar(pvApiCtx, piAddr))
    {
        sciprint("isScalar\n");
    }

    if(isSquareMatrix(pvApiCtx, piAddr))
    {
        sciprint("isSquareMatrix\n");
    }

    if(isEmptyMatrix(pvApiCtx, piAddr))
    {
        sciprint("isEmptyMatrix\n");
    }

    //no return value
    AssignOutputVariable(pvApiCtx, 0) = 1;
    return 0;
}

Scilab test script

check_matrix_dimension([1,2,3;4,5,6]);
check_matrix_dimension([1,2,3]);
check_matrix_dimension([1;2;3]);
check_matrix_dimension([1]);
check_matrix_dimension([1,2;3,4]);
check_matrix_dimension([]);

See also

  • sciprint — A C gateway function which displays standard messages to the user (same profile as the C printf function)
Report an issue
<< Boolean sparse writing (Scilab gateway) Low level functions Variable Reference (Scilab gateway) >>

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:
Tue Feb 25 08:50:45 CET 2020