matlab.tall.transform
通过将函数句柄应用于数据块来转换数组
句法
描述
Examples
将功能应用于高矢量
采用matlab.tall.transform
构建具有类似于另一个数组的属性的高零数组。
为AirlinesMall.CSV
data set. The data contains information about arrival and departure times of US flights. Extract the一种rrDelay
variable, which is a vector of arrival delays.
ds = tabulartextdatastore('airlinesmall.csv',,,,“治疗”,,,,'na');ds.selectedVariablenames = {'arrdelay''depdelay'};tt =高(DS);tx = tt.arrdelay
TX = MX1高柱向量8 8 21 13 4 59 3 11::
编写一个匿名函数,该功能创建具有与输入相同的大小和数据类型的零数组。
零状= @(in) zeros(size(in),'like',,,,in);
采用matlab.tall.transform
应用零状
function to the vector of arrival delays. The result is a tall vector of the same size, but whose values are all zero.
s = matlab.tall.transform(TX)
S = MX1高列矢量0 0 0 0 0 0 0 0 0 0:::
转换两个向量
Calculate the mean total flight delay from vectors of arrival and departure delays.
为AirlinesMall.CSV
data set. The data contains information about arrival and departure times of US flights. Extract the一种rrDelay
andDepdelay
变量,是到达和出发延迟的向量。
ds = tabulartextdatastore('airlinesmall.csv',,,,“治疗”,,,,'na');ds.selectedVariablenames = {'arrdelay''depdelay'};tt =高(DS);tx = tt.arrdelay;tY = tt.DepDelay;
这卑鄙的
函数将输入向量连接到矩阵中,总和每行(忽略NAN)中的值,然后计算平均值。显示该功能文件的内容。
type卑鄙的
函数d = sundelay(a,b)x = [a b];y = sum(x,2,'omitnan');d =平均值(y);结尾
采用matlab.tall.transform
应用卑鄙的
在每个数据块中的功能tX
andtY
。这result is the mean total delay in each block of data.
d = matlab.tall.transform(@meanDelay, tX, tY)
d = 7x1高柱矢量14.0621 11.1639 17.2311 15.1852 12.5860 19.8596 14.4036
该操作假设将每个数据块减少为标量值的结果可以适合内存。对于使用较小块大小的极大数据集和数据集,该假设可能不是正确的。
使用多个输出应用功能
在每行数据中找到最大值和该值的索引。
为AirlinesMall.CSV
data set. The data contains information about arrival and departure times of US flights. Extract the一种rrDelay
andDepdelay
变量,是到达和出发延迟的向量。
ds = tabulartextdatastore('airlinesmall.csv',,,,“治疗”,,,,'na');ds.selectedVariablenames = {'arrdelay''depdelay'};tt =高(DS);tx = tt.arrdelay;tY = tt.DepDelay;
这Maxdelay
function concatenates the input vectors, and then it finds the maximum arrival or departure delay duration and its column index. Display the contents of that file.
typeMaxdelay
函数[m,i] = maxDelay(a,b)x = [a b];[m,i] = max(x,[],2);结尾
采用matlab.tall.transform
应用Maxdelay
在每个数据块中的功能tX
andtY
。这result is the maximum arrival or departure delay for each row of data, as well as an index vector indicating which column the maximum value came from. An index of 1 indicates that the arrival delay in that row is larger, and an index of 2 indicates that the departure delay is larger.
[[M, idx] = matlab.tall.transform(@maxDelay, tX, tY)
M = Mx1 tall double column vector 12 8 21 13 4 63 3 11 : : idx = Mx1 tall double column vector 2 1 1 1 1 2 1 1 : :
Output Table with Different Variables
使用“输出样”
从中返回表的选项matlab.tall.transform
that has different variables from the input table.
创建一个具有两个随机值变量的高高表。
t= tall(table(rand(1e6,1),rand(1e6,1)))
T = 1,000,000x2 tall table Var1 Var2 _______ _______ 0.81472 0.90399 0.90579 0.94095 0.12699 0.80252 0.91338 0.24205 0.63236 0.97566 0.09754 0.31723 0.2785 0.81279 0.54688 0.69743 : : : :
这function曲雷德夫
计算两个输入表变量之间的差异,并将结果添加为表中的新变量。显示文件的内容。
type曲雷德夫
function Tout = tableDiff(Tin) d = Tin.Var2 - Tin.Var1; Tin.Var3 = abs(d); Tout = Tin; end
采用matlab.tall.transform
应用曲雷德夫
在每个数据块中的功能t
。由于输出表与输入表具有不同的变量,请使用“输出样”
名称值对提供具有与输出相似的变量的原型表(三个带有默认名称的变量Var1
,,,,Var2
,,,,andVar3
)。
Z = matlab.tall.transform(@tableDiff, T,“输出样”,,,,{table(1,1,1)})
Z = Mx3 tall table Var1 Var2 Var3 _______ _______ ________ 0.81472 0.90399 0.089267 0.90579 0.94095 0.035156 0.12699 0.80252 0.67553 0.91338 0.24205 0.67133 0.63236 0.97566 0.3433 0.09754 0.31723 0.21969 0.2785 0.81279 0.53429 0.54688 0.69743 0.15054 : : : : : :
输入参数
FCN
-transform function to apply
功能句柄|anonymous function
transform function to apply, specified as a function handle or anonymous function. Each output ofFCN
必须与第一个输入相同tX
。您可以使用“输出样”
返回不同数据类型的输出的选项。如果FCN
returns more than one output, then the outputs must all have the same height.
这general functional signature ofFCN
是
[a,b,c,...] = fcn(x,y,z,...)
FCN
must satisfy these requirements:
输入参数- 输入
[X,Y,Z,...]
是适合内存的数据块。这些块是通过从各个高阵列输入中提取数据来产生的[[tX, tY, tZ, ...]
。输入[X,Y,Z,...]
satisfy these properties:全部of
[X,Y,Z,...]
have the same size in the first dimension after any allowed expansion.数据块
[X,Y,Z,...]
come from the same index in the tall dimension, assuming the tall array is nonsingleton in the tall dimension. For example, iftX
andtY
是在高维度中的nonsingleton,然后第一组可能是x = tX(1:20000,:)
andy = tY(1:20000,:)
。如果the first dimension of any of
[[tX, tY, tZ, ...]
大小1
,然后是相应的块[X,Y,Z,...]
由该高阵列中的所有数据组成。
Output Arguments- 输出
[A,B,C,...]
are blocks that fit in memory, to be sent to the respective outputs[TA,TB,TC,...]
。这outputs[A,B,C,...]
satisfy these properties:全部of
[A,B,C,...]
必须在第一个维度中具有相同的大小。全部of
[A,B,C,...]
垂直与先前调用的结果相连FCN
。全部of
[A,B,C,...]
are sent to the same index in the first dimension in their respective destination output arrays.
Functional Rules-
FCN
must satisfy the functional rule:F([inputs1; inputs2]) == [F(inputs1); F(inputs2)]
:将函数应用于输入的串联应与将函数分别应用于输入,然后再串联结果。
空输入-Ensure that
FCN
可以处理其高度为0的输入。当文件为空时,可能会发生空输入,或者在数据上进行了大量过滤时。
例如,此功能接受两个输入数组,将它们平方并返回两个输出数组:
function[xx,yy] = sqinputs(x,y)xx = x。^2;yy = y。^2;结尾
tX
andtY
使用此命令:[ta,tb] = matlab.tall.transform(@sqinputs,tx,ty)
例子:tA = matlab.tall.transform(@(x) x .* 2, tX)
指定匿名函数以乘以tX
by 2.
例子:tc = matlab.tall.transform(@plus,tx,ty)
specifies a function handle@plus
to add two arrays together.
Data Types:function_handle
tX
,,,,tY
-输入数组
标量|向量|矩阵|多维阵列
输入数组,,,,specified as scalars, vectors, matrices, or multidimensional arrays. The input arrays are used as inputs to the specified functionFCN
。每个输入阵列TX,TY,...
必须具有兼容的高度。当两个输入的高度相同时,或一个输入为高度时,两个输入具有兼容的高度。
PA
,,,,PB
-输出阵列的原型
数组
输出数组的原型,指定为数组。指定时“输出样”
,,,,the output arraystA,tB,...
返回matlab.tall.transform
具有与指定数组相同的数据类型{PA,PB,...}
。
例子:ta = matlab.tall.transform(fcn,tx,'outputslike',{int8(1)});
,,,,wheretX
是一个双重精度阵列,返回一种
作为int8
代替double
。
Output Arguments
tA
,,,,tB
- 输出数组
标量|向量|矩阵|多维阵列
Output arrays, returned as scalars, vectors, matrices, or multidimensional arrays. If any input tomatlab.tall.transform
是高的,,,,then all output arguments are also tall. Otherwise, all output arguments are in-memory arrays.
这size and data type of the output arrays depend on the specified functionFCN
。In general, the outputstA,tB,...
必须所有人都具有与第一个输入相同的数据类型X
。但是,您可以指定“输出样”
返回不同的数据类型。输出数组tA,tB,...
所有人都有相同的高度。
更多关于
tall Array Blocks
When you create a tall array from a datastore, the underlying datastore facilitates the movement of data during a calculation. The data moves in discrete pieces called块or大块,其中每个块是一组连续行,可以适合内存。例如,二维数组的一个块(例如表)是x(n:m,:)
,,,,for some subscriptsn
andm
。每个块的大小基于ReadSize
property of the datastore, but the block might not be exactly that size. For the purposes ofmatlab.tall.transform
,高阵列被认为是许多这样的块的垂直串联:
例如,如果您使用sum
功能作为转换函数,结果是总和每块。这refore, instead of returning a single scalar value for the sum of the elements, the result is a vector with length equal to the number of blocks.
ds = tabulartextdatastore('airlinesmall.csv',,,,“治疗”,,,,'na');ds.selectedVariablenames = {'arrdelay''depdelay'};tt =高(DS);tx = tt.arrdelay;f = @(x)sum(x,'omitnan');s = matlab.tall.transform(f,tx);S =收集
S = 140467 101065 164355 135920 111182 186274 21321
MATLAB Command
您单击了与此MATLAB命令相对应的链接:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- AméricaLatina(Español)
- 加拿大(English)
- 美国(English)