Modify Repmat function to concatenate array

조회 수: 2 (최근 30일)
Santos García Rosado
Santos García Rosado 2021년 2월 9일
댓글: Santos García Rosado 2021년 2월 9일
Hello MathWorks community.
I'm trying to concatenate an array of my own "n" times. The thing is that each time each time I concatenate the array, I want to multiply it by 1, 10, 20...
For example, lets say my initial array is [0,1,2,3,4]. And that n =3. Then the output should look like:
out = [0,1,2,3,4,0,10,20,30,40,0,20,40,60,80]
I was wondering if I could use the repmat fucntion in some way to get this don, or is this function only useful for concatanating the exact same array?
Thank's for the help!
Santos

채택된 답변

Stephen23
Stephen23 2021년 2월 9일
V = [0,1,2,3,4];
n = 3;
X = [1,10*(1:n-1)];
Z = kron(X,V)
Z = 1×15
0 1 2 3 4 0 10 20 30 40 0 20 40 60 80
  댓글 수: 1
Santos García Rosado
Santos García Rosado 2021년 2월 9일
Didn't know about that function. Thank you Stephen.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Monika Jaskolka
Monika Jaskolka 2021년 2월 9일
If you want to understand how repmat works, take a look at the syntax and description in the documentation page: https://www.mathworks.com/help/matlab/ref/repmat.html.
I was able to do this using a loop:
n = 3;
init = [0, 1, 2, 3, 4];
out = init;
for i = 1:n-1
factor = 10*i;
out = horzcat(out, init.*factor);
end
  댓글 수: 1
Santos García Rosado
Santos García Rosado 2021년 2월 9일
Thank's Monika, the loop works aswell. I've read the documentation but still acan't figure out a way.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by