BSXFUN: Apply a function to each element of 2 arrays with singleton...

Description Usage Arguments Value Author(s) Source References Examples

View source: R/climtrends.R

Description

BSXFUN applies a function to each element of 2 arrays with singleton expansion enabled, clone of MATLAB's BSXFUN

Usage

1
BSXFUN(op, x, y)

Arguments

op

binary function to apply to arrays x and y

x

array of numeric or boolean values

y

array of numeric or boolean values

Value

array of numeric or boolean values with the result of function op applied to x and y

Author(s)

Jose Gama

Source

Douglas M. Schwarz, 2006 Generalized Array Operations http://www.mathworks.com/matlabcentral/fileexchange/10333-generalized-array-operations/content/genop.m

References

Douglas M. Schwarz, 2006 Generalized Array Operations http://www.mathworks.com/matlabcentral/fileexchange/10333-generalized-array-operations/content/genop.m

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#example 1
x<-matrix(c(17,24,1,8,15,23,5,7,14,16,4,6,13,20,22,10,12,19,21,3,11,18,25,2,9),
5,5,byrow=TRUE)
y<-matrix(13,1,5)
op<-'+'
BSXFUN(op,x,y)

#example 2
d1<-c(4,3,1,2)
x = array(runif(prod(d1)),d1)
d2<-c(4,1,5,2)
y = array(runif(prod(d2)),d2)
op<-'*'
BSXFUN(op,x,y)

#example 3
d1<-c(1,2,5,6,3)
x<-array(1:prod(d1),d1)
d2<-c(1,2,5,1,3,4)
y<-array(1:prod(d2),d2)
op<-'+'
BSXFUN(op,x,y)

climtrends documentation built on May 29, 2017, 11:58 p.m.