Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
empty []
empty matrix. Array ranges destructor.
Contents
Description
General [ ] properties
Empty brackets []
represent the empty matrix. Its general properties
are now described.
It has only two dimensions. Any dimension > #2 is automatically squeezed:
--> e = ones(1,2,0,2); size(e) ans = 0. 0. --> e == [] ans = T
It is always of real decimal type. There is no empty matrix of integer types (int8, uint8, int16, uint16, int32, uint32, int64, uint64), nor of string type, etc:
--> type(uint8([])) // not of type 8 (encoded integers) ans = 1. --> a = [1 2 ; 3 4] + %i; --> a(1,:) = [] a = 3. + i 4. + i --> a(1,:) = [], isreal(a) a = [] ans = T --> t = "abcd efg", type(t) t = abcd efg ans = 10. --> t(1) = [], type(t) t = [] ans = 1.
However, it is distinct from the sparse empty matrix:
--> se = sparse([]) se = ( 0, 0) zero sparse matrix --> size(se) ans = 0. 0. --> se == [] ans = F
It is also distinct from all empty heterogeneous containers
list()
,struct()
orcell()
:--> L = list() L = () --> L == [] ans = F --> s = struct() s = 0x0 struct array with no fields. --> s == [] ans = F --> c = cell() c = {} --> c == [] ans = F
[ ] as operand or input argument
As operand of usual predefined non-boolean operators, [] sets the result to []. All the following operations yield []:
Unary operators []', [].', -[], ~[] Binary numerical operators addition: [] + [1 2], [1 2] + [] subtraction: [] - [1 2], [1 2] - [] division: []/[1 2], []./[1 2], [1 2]/[], [1 2]./[] left division: []\[1 2], [].\[1 2], [1 2]\[], [1 2].\[] multiplication: []*[1 2], [].*[1 2], [1 2]*[], [1 2].*[] kronecker: [].*.[1 2], [1 2].*.[] power: []^[1 2], [].^[1 2], [1 2]^[], [1 2].^[] Inequality comparisons greater: []>[1 2], []>=[1 2], [1 2]>[], [1 2]>=[] less: []<[1 2], []<=[1 2], [1 2]<[], [1 2]<=[] As operand of boolean binary operators, [] is equivalent to %T:
But, noticeably:Binary numerical operators or: [] | [%T %F], [%T %F] | [] → [%T %T] and: [] & [%T %F], [%T %F] & [] → [%T %F] or([])
is %F.As the condition of any
if
orwhile
statement, [] is %F:--> if [] --> r = "[] is %T as any if condition"; --> else --> r = "[] is %F as any if condition"; --> end --> r r = [] is %F as any if condition
In concatenations, [] is simply ignored:
[A,[]] == [[],A] == [A ; []] == [[] ; A] == A
In text concatenations, +[] yields []:
[]+["a" "bc"] == ["a" "bc"]+[] == []
As special input matrix of linear algebra or common functions, the answer depends on the considered function. It is documented in the page dedicated to each function. Examples:
det([])
1
rank([])
0
trace([])
0
norm([])
0
cond([])
0
rcond([])
Inf
diag([])
[]
tril([])
[]
triu([])
[]
min([])
[]
max([])
[]
sign([])
[]
clean([])
[]
svd([])
[]
cumprod([])
[]
cumsum([])
[]
sum([])
0
prod([])
1
mean([])
Nan
median([])
Nan
stdev([])
Nan
mad([])
Nan
variance([])
Nan
As general input argument of functions, [] is often used to choose the default value of an input argument (to somewhat skip it, to avoid providing an actual explicit value). However, this is not a strict rule.
Assigning [ ] to delete ranges in arrays
Considering an array of any number of dimensions and of any size, that can be a matrix or hypermatrix of any datatype, an array of structures, or an array of cells, [] can be assigned to delete the addressed ranges (rows, columns, etc). These ones must cover the full size of the array at least along one of its dimensions.
Examples:
With a matrix of decimal numbers:
a = grand(3,5,"uin",0,9)
--> a = grand(3,5,"uin",0,9) a = 2. 4. 8. 0. 9. 2. 1. 3. 6. 4. 4. 9. 5. 9. 7. --> a(:,[3 5]) = [] a = 2. 4. 0. 2. 1. 6. 4. 9. 9. --> a(2,:) = [] a = 2. 4. 0. 4. 9. 9.
With an hypermatrix of texts:
cs = cumsum(grand(2,4,3,"uin",1,3)); t = matrix(strsplit(ascii(grand(1,cs($),"uin",ascii("a"),ascii("c"))),cs(1:$-1)),2,4,3)
--> cs = cumsum(grand(2,4,3,"uin",1,3)); --> t = matrix(strsplit(ascii(grand(1,cs($),"uin",ascii("a"),ascii("c"))),cs(1:$-1)),2,4,3) t = (:,:,1) !ccc b b b ! !bbb bcc bc c ! (:,:,2) !aa aab bc a ! !ab a cc ba ! (:,:,3) !c aba c abb ! !bc cc acb c ! --> t(:,3,:) = [] // Deleting all 3rd columns t = (:,:,1) !ccc b b ! !bbb bcc c ! (:,:,2) !aa aab a ! !ab a ba ! (:,:,3) !c aba abb ! !bc cc c ! --> t(:,:,2) = [] // Deleting the 2nd page t = (:,:,1) !ccc b b ! !bbb bcc c ! (:,:,2) !c aba abb ! !bc cc c !
With an array of cells:
c = cat(3, {"start", -1.23, %f ; (1-%s)^2, gda(), list(2,,%z)}, .. {%t , "abc", 5.2 ; int8(21), [] , %z})
--> c = cat(3, {"start", -1.23, %f ; (1-%s)^2, gda(), list(2,,%z)}, .. {%t , "abc", 5.2 ; int8(21), [] , %z}) c = (:,:,1) [1x1 string ] [1x1 constant] [1x1 boolean] [1x1 polynomial] [1x1 handle ] [ list ] (:,:,2) [1x1 boolean] [1x1 string ] [1x1 constant ] [1x1 int8 ] [0x0 constant] [1x1 polynomial] --> c(:,2,:) = [] // Deleting all 2nd columns c = (:,:,1) [1x1 string ] [1x1 boolean] [1x1 polynomial] [ list ] (:,:,2) [1x1 boolean] [1x1 constant ] [1x1 int8 ] [1x1 polynomial] --> c(1,:,:) = [] // Deleting all 1st rows c = (:,:,1) [1x1 polynomial] [ list] (:,:,2) [1x1 int8] [1x1 polynomial]
With an array of structures:
--> s(4,5).r = %pi; --> s.b = %t s = 4x5 struct array with fields: r b --> s([1 3],:) = [] s = 2x5 struct array with fields: r b --> s(:,2) = [] s = 2x4 struct array with fields: r b
Other examples
type(string([])) [type(int8([])) , type(int16([])) , type(int32([])) , type(int64([]))] [type(uint8([])), type(uint16([])), type(uint32([])), type(uint64([]))] [] * %F
--> type(string([])) ans = 1. --> [type(int8([])) , type(int16([])) , type(int32([])) , type(int64([]))] ans = 1. 1. 1. 1. --> [type(uint8([])), type(uint16([])), type(uint32([])), type(uint64([]))] ans = 1. 1. 1. 1. --> [] * %F ans = []
A = [%s-1, %s^2] A + [] A - [] A * []
--> A = [%s-1, %s^2] A = 2 -1 +s s --> A + [] ans = [] --> A - [] ans = [] --> A * [] ans = []
string([]) == [] ["a" "bc"] + [] [] + ["a" "bc"]
--> string([]) == [] ans = T --> ["a" "bc"] + [] ans = [] --> [] + ["a" "bc"] ans = []
A = rand(2,2); A([],:)
--> A = rand(2,2); --> A([],:) ans = []
--> [det([]) rank([]) trace([]) norm([]) cond([]) rcond([])] ans = 1. 0. 0. 0. 0. Inf
--> [sum([]) prod([]) mean([]) median([]) stdev([]) mad([])] ans = 0. 1. Nan Nan Nan Nan
See also
- null — deletes a list component or a field of a structure, Mlist, or Tlist
- isempty — 変数が空の行列または空のリストかどうかを調べる
- emptystr — 長さ0の文字列
- brackets — Concatenation. Recipients of an assignment. Results of a function
- operators — scilab 演算子の名前
- matrices — Scilab オブジェクト, Scilabの行列
- oldEmptyBehaviour — Controls the operation+ and operation- behaviour for Scilab
- insertion — 変数への部分的な代入または修正
History
バージョン | 記述 |
6.0.0 |
|
Report an issue | ||
<< diag | elementarymatrices | eye >> |