MATLAB: Is there a matlab function similar to base R “row” or “col”? It returns a matrix of integers indicating their row number in a matrix-like object.

r to matlab

In R, we may make a matrix-like object with row-number or column number using a base function. For example, in R:
x = diag(5) % R code
row(x)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 1 1 1
[2,] 2 2 2 2 2
[3,] 3 3 3 3 3
[4,] 4 4 4 4 4
[5,] 5 5 5 5 5
col(x)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] 1 2 3 4 5
[3,] 1 2 3 4 5
[4,] 1 2 3 4 5
[5,] 1 2 3 4 5
Is there a similar function in Matlab that does the job similar to base R 'row' or 'col'?

Best Answer

See ndgrid and meshgrid