xyzmatrix | R Documentation |
xyzmatrix
gets coordinates from objects containing 3D vertex data
xyzmatrix.list
will parse a list containing triplets of 3
numeric values.
xyzmatrix<-
assigns xyz elements of neuron or dotprops
object and can also handle matrix like objects with columns named X, Y, Z
or x, y, z.
xyzmatrix2str
will convert the XYZ locations associated
with an object to a character vector (by default comma separated).
xyzmatrix2list
will convert the Nx3 matrix of XYZ
locations associated with an object to a list of length N with each element
a vector of length 3.
xyzmatrix(x, ...)
## Default S3 method:
xyzmatrix(x, y = NULL, z = NULL, ...)
## S3 method for class 'list'
xyzmatrix(x, empty2na = TRUE, ...)
## S3 method for class 'character'
xyzmatrix(x, ...)
## S3 method for class 'neuron'
xyzmatrix(x, ...)
## S3 method for class 'neuronlist'
xyzmatrix(x, ...)
## S3 method for class 'shapelist3d'
xyzmatrix(x, ...)
## S3 method for class 'dotprops'
xyzmatrix(x, ...)
## S3 method for class 'hxsurf'
xyzmatrix(x, ...)
## S3 method for class 'igraph'
xyzmatrix(x, ...)
## S3 method for class 'mesh3d'
xyzmatrix(x, ...)
xyzmatrix(x) <- value
## S3 replacement method for class 'character'
xyzmatrix(x) <- value
xyzmatrix2str(x, format = "%g,%g,%g", sep = NULL)
xyzmatrix2list(x)
## S3 replacement method for class 'neuron'
xyzmatrix(x) <- value
## S3 replacement method for class 'dotprops'
xyzmatrix(x) <- value
## S3 replacement method for class 'hxsurf'
xyzmatrix(x) <- value
## S3 replacement method for class 'igraph'
xyzmatrix(x) <- value
## S3 replacement method for class 'shape3d'
xyzmatrix(x) <- value
## S3 replacement method for class 'mesh3d'
xyzmatrix(x) <- value
## S3 replacement method for class 'neuronlist'
xyzmatrix(x) <- value
## S3 replacement method for class 'shapelist3d'
xyzmatrix(x) <- value
x |
object containing 3D coordinates |
... |
additional arguments passed to methods |
y , z |
separate y and z coordinates |
empty2na |
Whether or not to convert empty elements ( |
value |
Nx3 matrix specifying new xyz coords |
format |
A |
sep |
A character vector specifying a separator string. Overrides
|
Note that xyzmatrix
can extract or set 3D coordinates in a
matrix
or data.frame
that either has exactly 3 columns
or has 3 columns named X,Y,Z or x,y,z. As of Nov 2020, if these
columns are character vectors, they will be correctly converted to numeric
(with a warning for any NA values). As of Jan 2021 if x
is a numeric
vector containing exactly 3 numbers it will be parsed as a 1x3 matrix.
Support has also been added for setting a list containing 3-vectors in each
element.
For xyzmatrix
: Nx3 matrix containing 3D coordinates
For xyzmatrix<-
: Original object with modified coords
xyzmatrix
can also both get and set 3D coordinates from a character
vector (including a single data frame column) in which each string encodes
all 3 coordinates e.g. "-1, 4, 10"
. It should handle a range of
separators such as spaces, tabs, commas, semicolons and ignore extraneous
characters such as brackets. Note that data are rounded by
zapsmall
in the replacement version to try to avoid cases
where rounding errors result in long strings of digits to the right of the
decimal place.
Replacement into character vectors introduces a number of corner cases when there are not exactly 3 numbers to replace in the target vector. We handle them as follows:
0 values in target, >0 in replacement: use a default pattern
1-2 values in target, same number of "good" values in replacement: insert those replacement value
1-2 values in target, different number of values in replacement: use
default pattern, give a warning
The default pattern will be the first entry in x
with 3 numbers.
Should there not be such a value, then the pattern will be "x, y,
z"
.
xyzmatrix
# see all available methods for different classes
methods('xyzmatrix')
# ... and for the assignment method
methods('xyzmatrix<-')
# basic usage
xyzmatrix(cbind(-1,2,3))
# character vector - useful e.g. when encoded in 1 column of a table
str123="(-1,+2,3)"
xyzmatrix(str123)
# replace
xyzmatrix(str123) <- xyzmatrix(str123)/3
str123
xyzmatrix(str123) <- xyzmatrix(str123)*3
str123
n=Cell07PNs[[1]]
xyzmatrix(n)<-xyzmatrix(n)
stopifnot(isTRUE(
all.equal(xyzmatrix(n),xyzmatrix(Cell07PNs[[1]]))
))
head(xyzmatrix2str(kcs20[[1]]))
head(xyzmatrix2str(kcs20[[1]], format="(%g;%g;%g)"))
# if you want to process the xyz locations (here rounded to nearest nm)
# you must extract them from complex objects yourself
xyzmatrix2str(round(xyzmatrix(kcs20[[1]])*1000), format="%d,%d,%d")[1:3]
xyzmatrix2list(kcs20[[1]])[1:2]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.