主要内容

matlab.tall.transform

通过将函数句柄应用于数据块来转换数组

描述

例子

tA= matlab.tall.transform(FCN,,,,tX应用功能句柄FCNto each堵塞数组tXand returns a transformed array,tA

例子

tA= matlab.tall.transform(FCN,,,,tX,,,,tY,,,,。。。)指定几个数组TX,TY,...that are inputs toFCN。每个数组的相同行都通过FCN; for example,fcn(tx(n:m,:),ty(n:m,:))。Inputs with a height of one are passed to every call ofFCN

例子

[[tA,,,,tB,...] = matlab.tall.transform(FCN,,,,tX,,,,tY,,,,。。。),,,,whereFCN是返回多个输出,返回数组的函数tA,tB,...,,,,each corresponding to one of the output arguments ofFCN。所有输出FCN必须具有相同的高度,并且输出数必须与从中请求的数字相同matlab.tall.transform

例子

[[tA,,,,tB,...] = matlab.tall.transform(___,“输出样”,{PA,,,,PB,...})指定输出tA,tB,...具有与原型数组相同的数据类型PA,PB,..., 分别。您可以在先前的语法中使用任何输入参数组合。

Examples

全部收缩

采用matlab.tall.transform构建具有类似于另一个数组的属性的高零数组。

AirlinesMall.CSVdata set. The data contains information about arrival and departure times of US flights. Extract the一种rrDelayvariable, 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.CSVdata set. The data contains information about arrival and departure times of US flights. Extract the一种rrDelayandDepdelay变量,是到达和出发延迟的向量。

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应用卑鄙的在每个数据块中的功能tXandtY。这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.CSVdata set. The data contains information about arrival and departure times of US flights. Extract the一种rrDelayandDepdelay变量,是到达和出发延迟的向量。

ds = tabulartextdatastore('airlinesmall.csv',,,,“治疗”,,,,'na');ds.selectedVariablenames = {'arrdelay''depdelay'};tt =高(DS);tx = tt.arrdelay;tY = tt.DepDelay;

Maxdelayfunction 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在每个数据块中的功能tXandtY。这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 : :

使用“输出样”从中返回表的选项matlab.tall.transformthat 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 : : : : : :

输入参数

全部收缩

transform function to apply, specified as a function handle or anonymous function. Each output ofFCN必须与第一个输入相同tX。您可以使用“输出样”返回不同数据类型的输出的选项。如果FCNreturns more than one output, then the outputs must all have the same height.

这general functional signature ofFCN

[a,b,c,...] = fcn(x,y,z,...)
FCNmust satisfy these requirements:

  1. 输入参数- 输入[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, iftXandtY是在高维度中的nonsingleton,然后第一组可能是x = tX(1:20000,:)andy = tY(1:20000,:)

    • 如果the first dimension of any of[[tX, tY, tZ, ...]大小1,然后是相应的块[X,Y,Z,...]由该高阵列中的所有数据组成。

  2. 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.

  3. Functional Rules-FCNmust satisfy the functional rule:

    • F([inputs1; inputs2]) == [F(inputs1); F(inputs2)]:将函数应用于输入的串联应与将函数分别应用于输入,然后再串联结果。

  4. 空输入-Ensure thatFCN可以处理其高度为0的输入。当文件为空时,可能会发生空输入,或者在数据上进行了大量过滤时。

例如,此功能接受两个输入数组,将它们平方并返回两个输出数组:

function[xx,yy] = sqinputs(x,y)xx = x。^2;yy = y。^2;结尾
将此功能保存到可访问的文件夹后,您可以将功能调用到SquaretXandtY使用此命令:
[ta,tb] = matlab.tall.transform(@sqinputs,tx,ty)

例子:tA = matlab.tall.transform(@(x) x .* 2, tX)指定匿名函数以乘以tXby 2.

例子:tc = matlab.tall.transform(@plus,tx,ty)specifies a function handle@plusto add two arrays together.

Data Types:function_handle

输入数组,,,,specified as scalars, vectors, matrices, or multidimensional arrays. The input arrays are used as inputs to the specified functionFCN。每个输入阵列TX,TY,...必须具有兼容的高度。当两个输入的高度相同时,或一个输入为高度时,两个输入具有兼容的高度。

输出数组的原型,指定为数组。指定时“输出样”,,,,the output arraystA,tB,...返回matlab.tall.transform具有与指定数组相同的数据类型{PA,PB,...}

例子:ta = matlab.tall.transform(fcn,tx,'outputslike',{int8(1)});,,,,wheretX是一个双重精度阵列,返回一种作为int8代替double

Output Arguments

全部收缩

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 calledor大块,其中每个块是一组连续行,可以适合内存。例如,二维数组的一个块(例如表)是x(n:m,:),,,,for some subscriptsnandm。每个块的大小基于ReadSizeproperty 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

在R2018B中引入