Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.4.1 - Русский

Change language to:
English - 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 >> call_scilab API (Scilab engine) > Double management

Double management

How to manage Scilab's variable read and write process using call_scilab and api_scilab

Description

This help describes how doubles and matrix of doubles can be handle through the Call Scilab API and api Scilab.

There are several functions which can be used to read / write from the memory of Scilab. These functions are described in dedicated pages.

Note that the default type of a numeric value in Scilab is double. For example, in a=1 or a=[1,2], a will be consider as a double.

Note: Access to variables is done through api Scilab (named variable).

Examples

/* 
 * Write a matrix into Scilab
 * B=[1 4 2 3; 
 *    3 9 8 2 ]
 * Note that it is done column by column
 */ 
double B[] = {1,3,4,9,2,8,3,2};   /* Declare the matrix */
int rowB = 2, colB = 4; /* Size of the matrix */
char variableNameB[] = "B";
SciErr sciErr;

/*
 * Write it into Scilab's memory 
 */
sciErr = createNamedMatrixOfDouble(pvApiCtx,variableNameB,rowB,colB, B); /* pvApiCtx is a global variable */
if(sciErr.iErr)
{
    printError(&sciErr, 0);
}

/*
 * Prior to Scilab 5.2:
 * C2F(cwritemat)(variableNameB, &rowB, &colB, B, strlen(variableNameB));
*/

printf("\n");
printf("Display from Scilab of B:\n");
SendScilabJob("disp(B);"); /* Display B */
/* Read the previously declared matrix of double B */
int rowB_ = 0, colB_ = 0, lp_ = 0;
double *matrixOfDoubleB = NULL;
int i = 0, j = 0;
char variableToBeRetrievedB[] = "B";
SciErr sciErr;

/* First, retrieve the size of the matrix */
sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, NULL);
if(sciErr.iErr)
{
    printError(&sciErr, 0);
}

/* 
 * Prior to Scilab 5.2:
 * C2F(cmatptr)(variableToBeRetrievedB, &rowB_, &colB_, &lp_, strlen(variableToBeRetrievedB));
 */

/* Alloc the memory */
matrixOfDoubleB = (double*)malloc((rowB_*colB_)*sizeof(double));

/* Load the matrix */
sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, matrixOfDoubleB);
if(sciErr.iErr)
{
    printError(&sciErr, 0);
}

/* 
 * Prior to Scilab 5.2:
 * C2F(creadmat)(variableToBeRetrievedB,&rowB_,&colB_,matrixOfDoubleB,strlen(variableToBeRetrievedB) );
 */

printf("\n");
printf("Display from B formated (size: %d, %d):\n",rowB_, colB_);
for(j = 0 ; j < rowB_ ; j++)
 {
  for(i = 0 ; i < colB_ ; i++)
   {
    /* Display the formated matrix ... the way the user
     * expect */
    printf("%5.2f ",matrixOfDoubleB[i * rowB_ + j]);
   }
  printf("\n"); /* New row of the matrix */
 }

See Also

Report an issue
<< DisableInteractiveMode call_scilab API (Scilab engine) GetLastJob >>

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 Apr 02 17:37:59 CEST 2013