Repeat copies of array elements (2024)

Repeat copies of array elements

collapse all in page

Syntax

u = repelem(v,n)

B = repelem(A,r1,...,rN)

Description

example

u = repelem(v,n),where v is a scalar or vector, returns a vectorof repeated elements of v.

  • If n is a scalar, then each elementof v is repeated n times. Thelength of u is length(v)*n.

  • If n is a vector, then it mustbe the same length as v. Each element of n specifiesthe number of times to repeat the corresponding element of v.

This syntax is not supported for table input.

example

B = repelem(A,r1,...,rN) returnsan array with each element of A repeated accordingto r1,...,rN. Each r1,...,rN musteither be a scalar or a vector with the same length as A inthe corresponding dimension. For example, if A isa matrix, repelem(A,2,3) returns a matrix containinga 2-by-3 block of each elementof A.

Examples

collapse all

Repeat Vector Elements

Open Live Script

Create a vector and repeat each of its elements three times into a new vector.

v = [1 2 3 4];u = repelem(v,3)
u = 1×12 1 1 1 2 2 2 3 3 3 4 4 4

Repeat the first two elements of v twice and the last two elements three times.

u = repelem(v,[2 2 3 3])
u = 1×10 1 1 2 2 3 3 3 4 4 4

Repeat Matrix Elements

Open Live Script

Create a matrix and repeat each element into a 3-by-2 block of a new matrix.

A = [1 2; 3 4]
A = 2×2 1 2 3 4
B = repelem(A,3,2)
B = 6×4 1 1 2 2 1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4 3 3 4 4

Repeat Matrix Columns

Open Live Script

Create a matrix and copy its columns into a new array, repeating the first column twice and second column three times.

A = [1 2; 3 4]
A = 2×2 1 2 3 4
B = repelem(A,1,[2 3])
B = 2×5 1 1 2 2 2 3 3 4 4 4

Combine Vector Elements

Open Live Script

Create two column vectors.

A = [1; 3; 5];B = [2; 4];

Generate all element combinations of the two vectors by using repelem and repmat. Each row of the output T is a combination with the first element coming from the first vector and the second element coming from the second vector. This command is equivalent to finding the Cartesian product of two vectors.

T = [repelem(A,numel(B)) repmat(B,numel(A),1)]
T = 6×2 1 2 1 4 3 2 3 4 5 2 5 4

Starting in R2023a, you can also use the combinations function to generate all element combinations of two vectors.

T = combinations(A,B)
T=6×2 table A B _ _ 1 2 1 4 3 2 3 4 5 2 5 4

Input Arguments

collapse all

vInput element
scalar | vector

Input element, specified as a scalar or a vector.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | datetime | duration
Complex Number Support: Yes

nNumber of times to repeat each element
scalar | vector

Number of times to repeat each element, specified as a scalaror a vector. If n is a scalar, then all elementsof v are repeated n times. If n isa vector, then each element of n specifies thenumber of times to repeat the corresponding element of v.In either case, n must be integer-valued.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

AInput array
matrix | multidimensional array

Input array, specified as a matrix or multidimensional array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | struct | table | cell | datetime | duration
Complex Number Support: Yes

r1,...,rNRepetition factors for each dimension (as separate arguments)
scalars | vectors

Repetition factors for each dimension, specified as separatearguments of integer-valued scalars or vectors. If A isa table, each repetition factor must be a scalar.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

u — Output vector
vector

Output vector. If v is a row vector or scalar, u isa row vector. If v is a column vector, u isalso a column vector.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | datetime | duration

B — Output array
matrix | multidimensional array

Output array, returned as a matrix or multidimensional array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | datetime | duration

Extended Capabilities

This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced in R2015a

See Also

kron | repmat

MATLAB-Befehl

Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:

 

Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.

Repeat copies of array elements (1)

Select a Web Site

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

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Repeat copies of array elements (2024)
Top Articles
The Artful Reinvention Of Klansman Asa Earl Carter
Project MUSE - Claiming the Unclaimable: Forrest Carter, The Education of Little Tree, and Land Claim in the Native South
Proto Ultima Exoplating
Tony's Delicatessen & Fresh Meats
Butte County Court Oroville Ca
Uscis Fort Myers 3850 Colonial Blvd
U-Bolts - Screws, Bolts variety of type & configurable | MISUMI Thailand
Officially Announcing: Skyward
Post-Tribune Obits
Zulrah Strat Osrs
Levidia 2019
Kinoprogramm für Berlin und Umland
Traveltalkonline
Cuộc thi “Chung tay vì an toàn giao thông” năm 2024
Probasketball Reference
Rooms For Rent Portland Oregon Craigslist
Rancho Medanos Schedule
Dayz Nyheim Map
P.o. Box 30924 Salt Lake City Ut
Nerdwallet American Express Gold
Real Caca Girl Leak
Elmira Star Gazette Obit
Theramed Junior Strawberry 6+ Tandpasta 75 ml - 12 stuks - Voordeelverpakking | bol
Standard Specification for Annealed or Cold-Worked Austenitic Stainless Steel Sheet, Strip, Plate, and Flat Bar
1773X To
Papa Johns Mear Me
Union Supply Direct Wisconsin
Metro By T Mobile Sign In
855-392-7812
Mybackpack Bolles
Www.cvs/Otchs/Simply
Realidades 2 Capitulo 2B Answers
Liveops Nation Okta Com Sign In
Wayne Carini How Tall
Thomas E Schneider Jeopardy
Ohio Licensing Lookup
Lenscrafters Westchester Mall
Entegra Forum
Fcs Punting Stats
Where Is Item Number On Stanley Cup
Glowforge Forum
The Stock Exchange Kamas
Smithfield Okta Login
11526 Lake Ave Cleveland Oh 44102
Jailfunds Send Message
Stroom- of gasstoring? | Stedin
Lbl A-Z
Mpbn Schedule
Www.888Tt.xyz
Amazing Lash Bay Colony
866-360-2863
Sammyflood
Latest Posts
Article information

Author: Msgr. Refugio Daniel

Last Updated:

Views: 5731

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Msgr. Refugio Daniel

Birthday: 1999-09-15

Address: 8416 Beatty Center, Derekfort, VA 72092-0500

Phone: +6838967160603

Job: Mining Executive

Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.