Ho to repeat a vector?
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (4 件)
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
2012 年 11 月 25 日
+1: While this is not very efficient, it is a creative recycling of the Signal Processing toolbox.
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(:)';
0 件のコメント
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);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!