Documentation

gather

Collect tall array into memory after executing queued operations

Syntax

Y = gather(X)
[y1,y2,y3,...] =收集(x1,x2,x3,...)

Description

example

Y= gather(X)executes all queued operations required to calculate unevaluated tall arrayX和collects the results into memory asY.

MATLAB®can run out of memory if the result of thegather计算太大。如果您不确定结果是否适合内存,请使用gather(head(X))或者gather(tail(X))要执行完整的计算,但仅将结果的一小部分带入内存。

Usegathersparingly to ensure that extra passes through the data are combined during the calculations whenever possible. For more information, seeDeferred Evaluation of Tall Arrays.

example

[Y1,Y2,Y3,...] = gather(X1,X2,X3,...)收集多个未评估的高阵列X1, X2, X3,...进入相应的输出Y1,Y2,Y3,....

Examples

collapse all

Create a datastore for theAirlinesMall.CSV数据集。选择一个可使用的变量子集,然后处理'NA'values as missing data so that数据store取代它们NaNvalues. Convert the datastore into a tall table.

varnames = {“年”,'ArrDelay',“唯一载体”}; ds = datastore('airlinesmall.csv','TreatAsMissing','NA',...'SelectedVariableNames',varnames);T =高(DS)
t = m×3个高桌年ard ardelay独立赛车____ _________________________ 1987 8'ps'1987 8'ps'1987 21'ps'1987 13'ps'1987 4'ps'ps'1987 59'ps'ps'ps'1987 3'ps'ps'ps'ps'1987 1987 1987 11 11'ps':::::::

Calculate the size of the tall table.

sz = size(T)
SZ = 1×2高的双行矢量??

MATLAB® does not immediately evaluate most operations on tall arrays. Instead, MATLAB remembers the operations you perform as you enter them and optimizes the calculations in the background.

When you usegatheron an unevaluated tall array, MATLAB executes all of the queued operations using the minimum number of passes through the data. This optimization greatly reduces the execution time of large calculations. For this reason, you should usegatheronly when you need to see a result.

Usegatherto execute the calculation and collect the result into memory.

s =gather(sz)
Evaluating tall expression using the Local MATLAB Session: - Pass 1 of 1: Completed in 0 sec Evaluation completed in 0 sec
s =123523 3

Usegatherwith several inputs to simultaneously evaluate several tall arrays.

Create a tall array from an in-memory array of random integers between 1 and 1000. Calculate the maximum and minimum values in each column.

A = tall(randi(1000,100,7))
a = 100×7高双矩阵815 163 645 60 423 583 583 851 906 795 379 682 95 541 541 561 561 127 312 812 43 599 870 930 914 914 914 914 914 529 529 533 72279 263 876 819 639 940 880 547 655 551 818 34 646 989::::::::::: :: :: :: ::: ::: ::: ::: ::: ::: ::: ::: ::: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
b = min(A); c = max(A);

Use the results to determine the overall minimum and maximum values in the array. Collect the final result into memory.

[mna,mxa] =收集(min(b),max(c));
Evaluating tall expression using the Local MATLAB Session: Evaluation completed in 0 sec
valrange =[mnA mxA]
valrange =1 1000

Input Arguments

collapse all

Unevaluated tall array. An unevaluated tall array is any tall array on which you perform calculations without usinggatherto fully evaluate those calculations.

Output Arguments

collapse all

内存阵列。数据类型Yis the same as the underlying data type of the unevaluated tall arrayX.

Tips

  • If you have Parallel Computing Toolbox™, seegather有关聚会的信息distributedgpuArraycomputations.

Introduced in R2016b

Was this topic helpful?