ASUBARRAYS

=ASUBARRAYS(a,r,c,f,i)

a
array
r
integer, row dim of subarrays
c
integer, column dim of subarrays
f
integer, format argument, 0 or ignored, compact format, 1, row format, 2, stack format. (active if i=0, no effect if i>0)
i
integer, index of the array to be extracted, when i>0 f argument has no effect, since the subarr extracted will have the predetermined format rxc

extracts subarrays of an array

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
ASUBARRAYS extracts subarrays of an array. calls ATEXTJOIN , ASTACK , AUNSTACK
Original idea credits to tboulden , different approach. The core of the formula is a simple concept based on a simple formula that extracts every subarray in rows format:
=LAMBDA(a,r,c,LET(w,ROWS(a),l,COLUMNS(a),x,l-c+1,y,w-r+1,m,SEQUENCE(,r*c),s,SEQUENCE(x*y),INDEX(IF(a<>"",a,""),QUOTIENT(m-1,c)+1+QUOTIENT(s-1,x),MOD(m-1,c)+1+MOD(s-1,x))))
Added to this other 2 formats that could be useful, and an explicit extraction of anyone of them, based on its index. Other functions on minisheet ASELECT , AAGGREGATE
Excel Formula:
=LAMBDA(a,r,c,f,i,
    LET(w,ROWS(a),l,COLUMNS(a),o,MEDIAN(1,r,w),u,MEDIAN(1,c,l),x,l-u+1,y,w-o+1,m,SEQUENCE(,o*u),s,SEQUENCE(x*y),
       z,INDEX(IF(a<>"",a,IF(f,""," ")),QUOTIENT(m-1,u)+1+QUOTIENT(s-1,x),MOD(m-1,u)+1+MOD(s-1,x)),
       t,ATEXTJOIN(z,"arr "&s&" =",,","),k,ASTACK(AUNSTACK(ASTACK(AUNSTACK(z,1),u),o),x*u),
       n,ASTACK(XLOOKUP(MEDIAN(i,1,x*y),s,z),u),q,SWITCH(f,0,t,1,z,2,k,"check format"),
       IF(i,n,q)
    )
)
subarrays.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
1sub 3x4compact format
2tot subs (5-3+1)*(6-4+1)=3*3=9arguments r=3,c=4,f=0,i=0arguments r=3,c=4,f=1,i=0 row formatsum every sub
3=ASUBARRAYS(A5:F9,3,4,,)=ASUBARRAYS(A5:F9,3,4,1,)=AAGGREGATE(J4#,5,)
4sample 5x6arr 1 =a,b,2,-3,5,d, ,3,-4,g,0,vab2-35d3-4g0v3max every sub
5ab2-30carr 2 =b,2,-3,0,d, ,3,e,g,0,v,10b2-30d3eg0v1012=AAGGREGATE(J4#,1,)
65d3efarr 3 =2,-3,0,c, ,3,e,f,0,v,10,x2-30c3ef0v10x125
7-4g0v10xarr 4 =5,d, ,3,-4,g,0,v,g,9,-4, 5d3-4g0vg9-4910
8g9-4rnarr 5 =d, ,3,e,g,0,v,10,9,-4, ,rd3eg0v109-4r1810
90szy8-2arr 6 = ,3,e,f,0,v,10,x,-4, ,r,n3ef0v10x-4rn99
10arr 7 =-4,g,0,v,g,9,-4, ,0,s,z,y-4g0vg9-40szy110
11arr 8 =g,0,v,10,9,-4, ,r,s,z,y,8g0v109-4rszy82310
12arr 9 =0,v,10,x,-4, ,r,n,z,y,8,-20v10x-4rnzy8-2129
1310
14also we can acomplish thisarguments r=3,c=4,f=2,i=0 stack format10
15with ASELECT=ASUBARRAYS(A5:F9,3,4,2,)
16=ASELECT(A5:F9,2,4,,4,)ab2-3b2-302-30c
175d03-ASUBARRAYS, like ASELECT5d3d3e3ef
18-4g0vcan be dynamic, but in a-4g0vg0v100v10x
19g9-40different manner5d3d3e3ef
20-4g0vg0v100v10x
21=ASELECT(A5:F9,3,,3,,)g9-49-4r-4rn
220v10x-4g0vg0v100v10x
23-40rng9-49-4r-4rn
24zy8-20szyszy8zy8-2
25extracts 9th sub arrayextracts 4th sub array
26other functionsarguments r=3,c=4,f=1,i=9arguments r=3,c=4,f=2,i=4
27ASELECT=ASUBARRAYS(A5:F9,3,4,1,9)=ASUBARRAYS(A5:F9,3,4,2,4)
28AAGGREGATE-when i argument >0, 0v10x5d3
29f argument is ignored-4rn-4g0v
30whatever value it haszy8-2g9-4
31
32- if we always want last array=ASUBARRAYS(A5:F9,3,4,,999)
33we can use a large i value0v10x
34-4 rn
35zy8-2
36
37-other sub dim example 5x5
38=ASUBARRAYS(A5:F9,7,8,2,)=ASUBARRAYS(A5:F9,5,5,2,)
39ab2-30c-if sub dim values exceedab2-30b2-30c
405d3efmain array dimensions,(7x8)5d3ed3ef
41-4g0v10xwill be downsized to main-4g0v10g0v10x
42g9-4rnarray dimensionsg9-4r9-4rn
430szy8-20szy8szy8-2
44
45=ASUBARRAYS(A5:F9,5,5,,10)
46b2-30c
47d 3ef
48g0v10x
499-4 rn
50szy8-2
51=ASUBARRAYS(A5:F9,5,5,1,)
52ab2-305d3e-4g0v10g9-4r0szy8
53b2-30cd3efg0v10x9-4rnszy8-2
54
Sheet2
Cell Formulas
RangeFormula
J3,A51,J45,J38,A38,J32,Q27,J27,A21,A16,J15,Y5,H3,W3J3=FORMULATEXT(J4)
H4:H12H4=ASUBARRAYS(A5:F9,3,4,,)
J4:U12J4=ASUBARRAYS(A5:F9,3,4,1,)
W4:W12W4=AAGGREGATE(J4#,5,)
Y6:Y14Y6=AAGGREGATE(J4#,1,)
J16:U24J16=ASUBARRAYS(A5:F9,3,4,2,)
A17:D19A17=ASELECT(A5:F9,2,4,,4,)
A22:D24A22=ASELECT(A5:F9,3,,3,,)
J28:M30J28=ASUBARRAYS(A5:F9,3,4,1,9)
Q28:T30Q28=ASUBARRAYS(A5:F9,3,4,2,4)
J33:M35J33=ASUBARRAYS(A5:F9,3,4,,999)
A39:F43A39=ASUBARRAYS(A5:F9,7,8,2,)
J39:S43J39=ASUBARRAYS(A5:F9,5,5,2,)
J46:N50J46=ASUBARRAYS(A5:F9,5,5,,10)
A52:Y53A52=ASUBARRAYS(A5:F9,5,5,1,)
Dynamic array formulas.
 
Upvote 0
Just updated my post to have a non-recursive, formula-based version; recursion depth was limiting factor on larger dimension arrays. Will play around with yours later to see if it suffers from similar limitations.
 

Forum statistics

Threads
1,224,837
Messages
6,181,255
Members
453,028
Latest member
letswriteafairytale

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top