Given the matrix:
matrix = ConstantArray[0, {3, 2}]
and date list:
list = {a, b, c, d, e, f}
a way to enter the list elements in the matrix is as follow:
matrix[[1,1]] = list[[1]];
matrix[[1,2]] = list[[2]];
matrix[[2,1]] = list[[3]];
matrix[[2,2]] = list[[4]];
matrix[[3,1]] = list[[5]];
matrix[[3,2]] = list[[6]];
getting what you want:
matrix == {{a, b}, {c, d}, {e, f}}
(*True*)
You could show a more elegant and effective way to do this?
Thanks so much.
Similarly, I can write:
matrix = ConstantArray[0, {3, 2}];
list1 = {a, b, c};
list2 = {d, e, f};
list3 = {g, h, i};
list4 = {j, k, l};
list5 = {m, n, o};
list6 = {p, q, r};
list = {list1, list2, list3, list4, list5, list6};
matrix[[1, 1]] = list[[1, 1]];
matrix[[1, 2]] = list[[2, 1]];
matrix[[2, 1]] = list[[3, 1]];
matrix[[2, 2]] = list[[4, 1]];
matrix[[3, 1]] = list[[5, 1]];
matrix[[3, 2]] = list[[6, 1]];
and obtain:
matrix == {{a, d}, {g, j}, {m, p}}
(*True*)
but I can not take advantage of the command that you kindly showed me.
In this other case, how can you do?
One last thing, instead of writing:
matrix[[1, 1]] = Grid[list[[1, 1]], Frame -> All, ItemSize -> All];
matrix[[1, 2]] = Grid[list[[2, 1]], Frame -> All, ItemSize -> All];
...
matrix[[3, 2]] = Grid[list[[6, 1]], Frame -> All, ItemSize -> All];
how can I do? I thought I was able to generalize the previous simple cases but I can not.
matrix = ArrayReshape[list, {3, 2}]? – Kuba Feb 12 '17 at 13:29matrixwithConstantArraybefore. Unless you want to fill part of a bigger matrix, but that is a different question. – Kuba Feb 12 '17 at 13:31Partition[list, 2]– Bob Hanlon Feb 12 '17 at 13:44