-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdiag_matlab.Rd
54 lines (50 loc) · 1.35 KB
/
diag_matlab.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/diag_matlab.R
\name{diag_matlab}
\alias{diag_matlab}
\title{Function written to match MATLAB's diag function}
\usage{
diag_matlab(mat)
}
\arguments{
\item{mat}{Either a vector to make into a diagonal matrix or a matrix you
want to extract the diagonal from}
}
\value{
Either a diagonal matrix or the diagonal of a matrix.
}
\description{
There are some differences between tha MATLAB and the R version of diag.
Specifically, if a 1xN or a Nx1 matrix is supplied to the R
\code{\link{diag}} function then just the first element of this vector is
returned. This function tries to match the MATLAB version in handling vectors
(matricies with one dimension equal to one), and will return a diagonal
matrix in these situations.
}
\examples{
diag_matlab(3)
diag_matlab(c(1,2,3))
diag_matlab(cbind(1,2,3))
diag_matlab(rbind(1,2,3))
diag_matlab(matrix(c(1, 2, 3),6,6))
# here is where the R default does something different
diag(cbind(1,2,3))
diag(rbind(1,2,3))
}
\seealso{
Other MATLAB:
\code{\link{cell}()},
\code{\link{feval}()},
\code{\link{fileparts}()},
\code{\link{isempty}()},
\code{\link{ones}()},
\code{\link{rand}()},
\code{\link{randn}()},
\code{\link{size}()},
\code{\link{tic}()},
\code{\link{toc}()},
\code{\link{zeros}()}
}
\concept{MATLAB}
\concept{matrix_manipulation}
\keyword{internal}