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


minus

(-) subtraction operator. Sign change

Syntax

X - Y
-X

Arguments

X, Y

scalars, vectors, matrices, or hypermatrices of booleans, numbers, polynomials or rationals. They may also be some syslin lists.

Description

Subtraction

For numeric operands, the subtraction has its usual meaning. If one of the operands is a scalar, then the substraction is performed with each component of the other operand.

As soon as a boolean is involved in a substraction with a number (decimal, complex, or encoded integer), it is automatically converted in the type (and integer type) of the number before performing the substraction or the sign change, as %F => 0 and %T => 1.

Whatever is the (regular) type of X, then []-X, X-[], and -[] return [].

The subtraction operator may be extended to other custom data types through the overloading mechanism.

Examples

[] - 2
1 - []
[2, 5] - 1
[2, 5] - [3 -2]

%s - 2
1/%s - 2
--> [] - 2
 ans  =
    []

--> 1 - []
 ans  =
    []

--> [2, 5] - 1
 ans  =
   1.   4.

--> [2, 5] - [3 -2]
 ans  =
  -1.   7.

--> %s - 2
 ans  =
  -2 +s

--> 1/%s - 2
 ans  =
   1 - 2s
   -------
     s

With booleans:

-[%f %t]
[%f %f %t %t]  - [%f %t %f %t]
%t - %i
c = %t - int8(7), inttype(c)
--> -[%f %t]
 ans  =
   0.  -1.

--> [%f %f %t %t]  - [%f %t %f %t]
 ans  =
   0.  -1.   1.   0.

--> %t - %i
 ans  =
   1. - i

--> c = %t - int8(7), typeof(c)
 c  =
 -6

 ans  =
 int8

See also

  • plus — Numerical addition. Text concatenation (gluing)
  • operators — scilab operator names
  • overloading — display, functions and operators overloading capabilities
  • oldEmptyBehaviour — Controls the operation+ and operation- behaviour for Scilab
  • mtlb_s — Matlab subtraction emulation function

History

VersionDescription
6.0.0 A - [] and [] - A now return [] instead of A or -A.
Report an issue
<< less Scilab keywords not >>

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 Oct 24 11:13:05 CEST 2024