How an array with 'n' elements, and replicate each element 'm' times and then replace it in the array ?
古いコメントを表示
Hello I need some help, I have a random array of e.g. 10 elements
A= [1 -1 1 1 -1 -1 -1 1 1 -1],
I want to replicate each element in the e.g. 3 times so new array becomes becomes like
B= [1 1 1 -1 -1 -1 1 1 1 1 1 1 -1 -1 -1 .......] and so on,
Can anyone tell me which function would be suitable or any logic that can be applied, as the random array has originally longer lengths and the replication values are higher. I don't want to replicate the whole array 'm' times but each element in array should be replicated as 1 replicated and replaced by 1 1 1 and -1 would be as -1 -1 -1.
Any help would be really appreciated.
採用された回答
その他の回答 (2 件)
Jos (10584)
2014 年 3 月 12 日
A = [1 4 3 2]
m = 3
B = kron(A, ones(1,m))
Image Analyst
2014 年 3 月 12 日
If you have the Image Processing Toolbox:
B = imresize(A, [1, 3*size(A,2)], 'nearest')
3 件のコメント
Haseeb Mufti
2014 年 3 月 12 日
Image Analyst
2014 年 3 月 13 日
I don't see why you need to do that if you can use imresize().
Image Analyst
2014 年 3 月 13 日
Since you now accepted the repmat answer I guess you don't have the IPT. But that's fine, whatever works.
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!