Translated squeeze
This commit is contained in:
parent
6389a4104c
commit
9c5beeda43
2 changed files with 51 additions and 0 deletions
22
R/squeeze.R
Normal file
22
R/squeeze.R
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#' @title Squeeze
|
||||||
|
#' @description Remove dimensions of length 1
|
||||||
|
#' @details This function implements the behavior of the homonimous function on
|
||||||
|
#' Matlab. `B = squeeze(A)` returns an array with the same elements as the
|
||||||
|
#' input array A, but with dimensions of length 1 removed. For example, if A is
|
||||||
|
#' a 3-by-1-by-1-by-2 array, then squeeze(A) returns a 3-by-2 matrix. If A is a
|
||||||
|
#' row vector, column vector, scalar, or an array with no dimensions of length
|
||||||
|
#' 1, then squeeze returns the input A.
|
||||||
|
#' @param A input or array matrix
|
||||||
|
#' @return An array with the same elements as the input array, but with
|
||||||
|
#' dimensions of length 1 removed.
|
||||||
|
#' @author Waldir Leoncio
|
||||||
|
squeeze <- function(A) {
|
||||||
|
A <- as.array(A)
|
||||||
|
dim_1 <- which(dim(A) == 1)
|
||||||
|
B <- array(A, dim = dim(A)[-dim_1])
|
||||||
|
|
||||||
|
# Workaround to match Matlab behavior
|
||||||
|
if (length(dim(B)) == 1) B <- as.matrix(B)
|
||||||
|
|
||||||
|
return(B)
|
||||||
|
}
|
||||||
29
man/squeeze.Rd
Normal file
29
man/squeeze.Rd
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/squeeze.R
|
||||||
|
\name{squeeze}
|
||||||
|
\alias{squeeze}
|
||||||
|
\title{Squeeze}
|
||||||
|
\usage{
|
||||||
|
squeeze(A)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{A}{input or array matrix}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
An array with the same elements as the input array, but with
|
||||||
|
dimensions of length 1 removed.
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Remove dimensions of length 1
|
||||||
|
}
|
||||||
|
\details{
|
||||||
|
This function implements the behavior of the homonimous function on
|
||||||
|
Matlab. `B = squeeze(A)` returns an array with the same elements as the
|
||||||
|
input array A, but with dimensions of length 1 removed. For example, if A is
|
||||||
|
a 3-by-1-by-1-by-2 array, then squeeze(A) returns a 3-by-2 matrix. If A is a
|
||||||
|
row vector, column vector, scalar, or an array with no dimensions of length
|
||||||
|
1, then squeeze returns the input A.
|
||||||
|
}
|
||||||
|
\author{
|
||||||
|
Waldir Leoncio
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue