I have a list such as { {1 ,1 }, "Q"}, { {2 ,3 }, "E"}, { {3 ,5 }, "Q"}, { {4 ,2 }, "Q"}, { {5 ,4 }, "Q"}, { {1 ,5 }, "E"}, and I need to show the characters in a rectangular grid, for example, in this case, 5*5 grid, such that on (1, 1), there is a char Q, on (2, 3) there is a letter Q, …, and on (1, 5) there is a letter E. And all the remaining positions in the grid is shown as blank.
Please help me.
SparseArrayis set up to do this. This also uses@@@which is short forApplyat level 1:The second argument of
SparseArray(here{5, 5}) is the explicit array size. You can useAutomaticto have it sized to the farthest point of your data. The third (optional) argument is the expression to use as the “background” of the array. Here I use an empty string""to meet your request for “blank.” Since this becomes hard to read you may prefer grid lines: