Learn R Programming

popdemo (version 0.1-2)

R2Matlab: Convert matrices into Matlab style strings

Description

Convert Robjects of class matrix into character strings that represent the matrix in a Matlab style

Usage

R2Matlab(A, noquote=FALSE)

Arguments

A
a numeric matrix of any dimension
noquote
(optional) if noquote=TRUE then the returned character vector is printed without quotes.

Value

  • Object of class character representing A in a Matlab style.

Details

Matlab reads matrices using a unique one-line notation that can prove useful for storage in databases and importing multiple matrices into a program at once, amongst other applications. This notation is by row, with "[" and "]" to specify the beginning and end of the matrix respectively, ";" to specify a new row and a space between each matrix element. Thus, the Rmatrix created using matrix(c(0,1,2,0.5,0.1,0,0,0.6,0.6), byrow=TRUE, ncol=3) may is equivalent to [0 1 2;0.5 0.1 0;0 0.6 0.6]. R2Matlab takes an Robject of class matrix and uses string-building techniques to convert it into a Matlab-style character string that may be useful for exporting into databases.

See Also

Matlab2R

Examples

Run this code
# Create a 3x3 PPM
    A <- matrix(c(0,1,2,0.5,0.1,0,0,0.6,0.6), byrow=TRUE, ncol=3)
    A

    # Code the matrix in a Matlab style
    R2Matlab(A)

    # Print without quotes
    R2Matlab(A, noquote=TRUE)

Run the code above in your browser using DataLab