Ho to repeat a vector?

조회 수: 1 (최근 30일)
M G
M G 2012년 11월 24일
댓글: Jordan Lessentier 2017년 5월 2일
Hi all,
Could anybody plz be a help me what is the build-in function for:
repvec (1:5, 2)
which results in:
ans = 1 1 2 2 3 3 4 4 5 5
Thank you so much for your help :)
  댓글 수: 1
Jordan Lessentier
Jordan Lessentier 2017년 5월 2일
https://fr.mathworks.com/help/matlab/ref/repelem.html

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

답변 (4개)

Matt Fig
Matt Fig 2012년 11월 24일
편집: Matt Fig 2012년 11월 24일
vec = 1:5;
reshape(vec([1 1],:),1,[])
% Or reshape(vec(ones(1,N),:),1,[]) to expand N times
For more complex expansions, give this file a try: EXPAND

Image Analyst
Image Analyst 2012년 11월 24일
If you have the Image Processing Toolbox, you can do it this way
out = imresize(a, [1 10], 'nearest')
where a is your 1:5 vector, and the 10 is how long you want the output to be.
  댓글 수: 1
Jan
Jan 2012년 11월 25일
+1: While this is not very efficient, it is a creative recycling of the Signal Processing toolbox.

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


Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 24일
편집: Azzi Abdelmalek 2012년 11월 24일
vec=1:5
out=[vec;vec];
out=out(:)'
If you want to repeat n times
vec=1:5
n=10;
out=repmat(vec,n,1);
out=out(:)';

Jan
Jan 2012년 11월 25일
While I'd prefer Matt Fig's approach in real programs, here another approach, which might be interesting:
vec = 1:5;
n = 2;
index = zeros(1, length(vec) * n);
index(1:n:end) = 1;
index = cumsum(index);
result = vec(index);

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by