Matlab如何在数组中插入n个相同元素。

用matlab做图像处理,现在需要将图像[m*n]坐标转存到两个列向量[mn*2],每个列向量存的是图像各个点的坐标。
例:
3*3的img,他的坐标为
(1,1
1,2
1,3
2,1
2,2
2,3
3,1
3,2
3,3)
第二列的123 123 123可以用repmat得到,而像第一列 111 222 333应该如何实现(图像较大,for循环比较费时:'( )
希望路过的朋友们帮帮我:hug:

 Accepted Answer

[repelem(1:3,3)',repmat([1:3]',3,1)]
如果你的版本低,没有repelem,就都用repmeat

More Answers (0)

Categories

Find more on MATLAB 快速入门 in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!