Create a repeating column matrix based on the min and max vector

lets say that my inputs are: v = [1, 3] and i = 4; I need to build this

1 1 1 1
2 2 2 2 
3 3 3 3

Any help please, how can I do this? All I know is this =>

V = (min(v):1:max(v));
V = V(:);

so i get

1
2
3

What should I do now? Thanks in advance!

+4
source share
1 answer

You are looking for : ndgrid

v = [1, 3]
ii = 4

out = ndgrid(v(1):v(end),1:ii)

out =

     1     1     1     1
     2     2     2     2
     3     3     3     3
+4
source

Source: https://habr.com/ru/post/1618770/


All Articles