lettura simple

Scilab's size() Function

In Scilab, the size() function plays a pivotal role by determining the dimensions of a matrix or an array. Consider the syntax:

size(x)

In this context, 'x' denotes either a matrix or an array.

Depending on its application, the function can yield the number of rows, columns, or both.

When working with matrices or arrays, this function becomes indispensable. Before delving into operations like matrix multiplication, it's paramount to verify the dimensional compatibility of the matrices involved.

To illustrate, let's walk through an example.

Suppose you define a 2x3 matrix with two rows and three columns as:

M = [1, 2, 3; 4, 5, 6]

To ascertain the matrix's dimensions, employ the size() function

size(M)

This will produce two distinct values: 2 and 3.

ans=
2. 3.

Here, the first value represents the matrix's row count, and the second denotes its columns.

For a specific row count, input size(M, 1)

size(M, 1)

ans =
2.

Conversely, to determine the column count, input size(M, 2)

ans =
3.

Interestingly, even for vectors (one-dimensional arrays), the size() function provides two values.

For example, let's define a vector with six values in a singular row:

V = [ 1, 2, 3, 4, 5, 6]

To extract its dimensions, utilize the size() function

size(V)

This results in:

1. 6.

Interpreting this, the vector's elements span one row (1) and are distributed across six columns (6), making it analogous to a 1x6 matrix.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin