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

Change language to:
English - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Aide de Scilab >> API call_scilab (moteur Scilab) > Complex management

Complex management

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

Description

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

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

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

Examples

/* 
 * Write a matrix into Scilab
 * B=[1+%i 4-%i 2+1/2*%i 3; 
 *    3 9 8+42*%i 2 ]
 * Note that it is done column by column
 */ 

double B[]={1,3,4,9,2,8,3,2};
double B_img[]={1,0.233,-1,-0.2,0.5,42,-23,123};   /* Declare the matrix */

/*
 * Prior to Scilab 5.2:
 * double B[]={1,3,4,9,2,8,3,2,1,0.233,-1,-0.2,0.5,42,-23,123};
*/

int rowB=2, colB=4; /* Size of the matrix */
char variableNameB[] = "B";
SciErr sciErr;

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

/*
 * Prior to Scilab 5.2:
 * 2F(cwritecmat)(variableNameB, &rowB, &colB, B, strlen(variableNameB));
 */
printf("\n");
printf("Display from Scilab of B:\n");
SendScilabJob("disp(B);"); /* Display B */
int rowB_ = 0, colB_ = 0, lp_ = 0;
int i = 0,j = 0;

double *matrixOfComplexB = NULL;
double *matrixOfComplexB_img = NULL;
char variableToBeRetrievedB[] = "B";
SciErr sciErr;

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

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

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

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

/*
 * Prior to Scilab 5.2:
 * C2F(creadcmat)(variableToBeRetrievedB,&rowB_,&colB_,matrixOfComplexB,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 + %5.2f.i  ",matrixOfComplexB[i * rowB_ + j],matrixOfComplexB_img[i * rowB_ + j]);

   }
  printf("\n"); /* New row of the matrix */
 }

See Also

Report an issue
<< Boolean management API call_scilab (moteur Scilab) DisableInteractiveMode >>

Copyright (c) 2022-2023 (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:
Fri Apr 11 14:15:06 CEST 2014