Main Content

收集

执行排队操作后,将高阵列收集到记忆中

描述

例子

y=聚集(X执行所有计算未评估的高阵列所需的排队操作X并将结果收集到记忆中y

MATLAB®如果记忆的结果可能会用完收集calculation is too large. If you are unsure whether the result can fit in memory, use收集(头(x))or收集(尾巴(x))to perform the full calculation, but bring only a small portion of the result into memory.

利用收集谨慎地确保在可能的情况下在计算过程中合并额外的通过数据。有关更多信息,请参阅延期对高阵列的评估

例子

[[y1,y2,,y3,...] =收集(X1,X2,,X3,...))收集s multiple unevaluated tall arraysx1,x2,x3,...into the corresponding outputsy1,y2,,y3,...

例子

全部收缩

airlinesmall.csvdata set. Select a subset of variables to work with, and treat'na'值为缺少数据,以便tabularTextDatastorereplaces them with值。将数据存储转换为高高的桌子。

varnames = {'年',,,,'arrdelay',,,,'UniqueCarrier'};ds = tabulartextdatastore('airlinesmall.csv',,,,“治疗”,,,,'na',,,,...“选择的variablenames”,,,,varnames); T = tall(ds)
T = Mx3 tall table Year ArrDelay UniqueCarrier ____ ________ _____________ 1987 8 {'PS'} 1987 8 {'PS'} 1987 21 {'PS'} 1987 13 {'PS'} 1987 4 {'PS'} 1987 59 {'PS'} 1987 3 {'PS'} 1987 11 {'PS'} : : : : : :

计算高桌子的大小。

sz = size(t)
SZ = 1x2高双行矢量??

MATLAB®不会立即评估高阵列上的大多数操作。相反,MATLAB记得您在输入它们时执行的操作并在后台优化计算。

当您使用时收集在未评估的高阵列中,MATLAB使用数据的最小通过数量执行所有排队的操作。这种优化大大减少了大计算的执行时间。因此,您应该使用收集只有当您需要查看结果时。

利用收集执行计算并将结果收集到内存中。

S =收集(SZ)
使用本地MATLAB会话评估高高的表达: - 通过1:Of 1:在1秒内完成的评估完成了1.3秒
S =1×2123523 3

利用收集有几个输入可以同时评估几个高阵列。

从1到1000之间的随机整数内存中创建一个高阵列。计算每列中的最大值和最小值。

a =高(randi(1000,100,7))
A = 100x7 tall double matrix 815 163 645 60 423 583 851 906 795 379 682 95 541 561 127 312 812 43 599 870 930 914 529 533 72 471 265 697 633 166 351 522 696 319 583 98 602 940 97 700 120 816 279 263 876 819 639 940 880 547 655 551 818 34 646 989 : : : : : : : : : : : : : :
b = min(a);c = max(a);

使用结果确定阵列中的总体最小值和最大值。将最终结果收集到内存中。

[[mnA,mxA] = gather(min(b),max(c));
Evaluating tall expression using the Local MATLAB Session: - Pass 1 of 1: Completed in 0.33 sec Evaluation completed in 0.71 sec
valrange = [MNA MXA]
valRange =1×21 1000

输入参数

全部收缩

未评估的高阵列。一个未评估的高阵列是您执行计算的任何高阵列,而无需使用收集充分评估这些计算。

输出参数

全部收缩

In-memory array. The data type ofy与未评估的高阵列的基础数据类型相同X

提示

  • 如果您具有并行计算工具箱™,请参见收集(并行计算工具箱)for information about gathering分散式andgpuarray计算。

扩展功能

高阵列
用比在内存中拟合更多的行的数组计算。

GPU代码生成
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

在R2016b中引入