Contents
How to store the result in a logical matrix?
Store the result in B. The result is a logical matrix. Each value in B represents a logical 1 ( true) or logical 0 ( false) state to indicate whether the corresponding element of A fulfills the condition A < 9. For example, A (1,1) is 13, so B (1,1) is logical 0 ( false ). However, A (1,2) is 2, so B (1,2) is logical 1 ( true ).
How do you extract an element from a matrix?
However, often you need to extract certain elements from a matrix. The SAS/IML language supports two ways to extract elements: by using subscripts or by using indices . Use subscripts when you are extracting a rectangular portion of a matrix, such as a row, a column, or a submatrix.
How to know which elements are less than 9 in a matrix?
Although B contains information about which elements in A are less than 9, it doesn’t tell you what their values are. Rather than comparing the two matrices element by element, you can use B to index into A. The result is a column vector of the elements in A that are less than 9.
How are matrices added in a matrix calculator?
If the matrices are the same size, matrix addition is performed by adding the corresponding elements in the matrices. For example, given two matrices, A and B, with elements ai,j, and bi,j, the matrices are added by adding each element, then placing the result in a new matrix, C, in the corresponding position in the matrix:
Can a logical matrix be used as an index?
Since B is a logical matrix, this operation is called logical indexing. In this case, the logical array being used as an index is the same size as the other array, but this is not a requirement. For more information, see Array Indexing.
How to find the nonzero elements in a matrix?
[row,col,v] = find ( ___) also returns vector v , which contains the nonzero elements of X. Find the nonzero elements in a 3-by-3 matrix. Use the logical not operator on X to locate the zeros. Find the first five elements that are less than 10 in a 4-by-4 magic square matrix.
What happens when you execute find with x > 1?
When you execute find with a relational operation like X>1, it is important to remember that the result of the relational operation is a logical matrix of ones and zeros. For example, the command [row,col,v] = find(X>1) returns a column vector of logical 1 ( true ) values for v.