

#Matriz scilab code
This way the code is more simple, compact and robust. If we are interested in all the elements of the columns for a particular row it makes sense to use the colon operator because we don’t have to specify the index for the first and last column. For example if we want to extract only the first 3 columns, corresponding to the 2nd row: ->testRow = testMatrix(2,1:3) testRow = 11.

This method makes sense to use only if we want to extract just a part of the columns, not all of them. Since we know that we have 4 columns, we tell Scilab to extract the values starting with the 1st column up to the 4th column, corresponding to the 2nd row: ->testRow = testMatrix(2,1:4) testRow = 11.

>Īnother method of doing the same extraction is using the explicit definition of the start and end column index. Basically this tells Scilab to extract the values from all the columns corresponding to the second row: ->testRow = testMatrix(2,:) testRow = 11. To do this, as arguments of the matrix we insert the row index, followed by the colon operator. We want to extract the second row from out test matrix and put the values into a new variable named testRow. There are several ways of doing this and we’ll learn a couple of techniques.įirst method of row extraction is using the colon operator “:” Suppose we want to extract a complete row from out test matrix. In the same way we can extract whatever value we want from the matrix just by specifying the index of the row and column. >testElement = testMatrix(2,3) testElement = 13. For example we want to put in a separate variable, named testElement, the value from line 2 and column 3 of the matrix. To extract just one element from a matrix we have to specify from which row and what column we want our value to be extracted. We’ll define a non-square matrix, named testMatrix, with 3 rows and 4 columns just to make this example more generic: ->testMatrix = one column, one row, a sub-matrix).įirst let’s define a matrix which is going to be our test variable.
#Matriz scilab how to
In this article we’ll learn how to extract a particular value from a matrix or a particular set of values (e.g. So far we have learned how to define a matrix in Scilab.
