Hi, I have an array a = [1 2 3] and I want to repeat it twice so I'll have b = [1 2 3 1 2 3]. I try this code, and of course it won't work as I want.
a = 1:3;
for n = 1:2
b = a;
end
b
I don't know what I should write in the for-loop. Could anyone help me? Thank you.

 채택된 답변

Youssef  Khmou
Youssef Khmou 2015년 1월 30일
편집: Youssef Khmou 2015년 1월 30일

0 개 추천

Many solutions exist for this problem, the first one is the repmat solution:
a=[1 2 3];
b=repmat(a,1,3);
The second solution consists of using for loop as follows :
b=[];
for n=1:3
b=[b a];
end

댓글 수: 2

arina octave
arina octave 2015년 1월 30일
hi Youssef, thank you so much for answering my question again!
Youssef  Khmou
Youssef Khmou 2015년 1월 30일
편집: Youssef Khmou 2015년 1월 30일
You are welcome Arina.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 1월 30일

편집:

2015년 1월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by