Question: I have a matrix X `e.g = [a b; c d; e f]`.

I need to create another matrix listing the index positions and values of the matrix.

e.g. The output is `E = [ 1 1 a ; 1 2 b ; 2 1 c ; 2 2 d ; 3 1 e ; 3 2 f ]`

I have been trying to use a double for loop but even if it did work, that sounds like a bad idea.

So can anyone has a better idea to perform above task?

Answer: 
Here is the dumbest thing I could think of (Assuming that `a,b,c,d,e,f` are all scalars)

```
x = [1 2;3 4;5 6];
[i,j]=ind2sub(size(transpose(x)), 1:numel(x));
[j(:) i(:) reshape(transpose(x),[],1)]

```

However, I have a feeling that there might be an answer that is more elegant.
Nothing wrong with @Andrey's answer, but because I like to find reasons to use `kron` :)

```
A = [1 2; 3 4; 5 6];

[nrows, ncols] = size(A);

M = [kron([1 : nrows]', ones(ncols, 1))...
    kron(ones(nrows, 1), [1 : ncols]')...
    reshape(A', [], 1)]

```