I have the following problem. I have a table, call it m, which is labelled by 3 indices (say i,j,k), each of them running from 1 up to 100.

I would like to be able to construct a new table which would consist of elements taken from m under the following condition:

For any p, such that 2 < p < 301, construct the table consisting of pairs, where the first term in all pairs for a given p is always the same equal p*0.06 Table[{0.06*p, m[[i, j, k]]}, {p, 2, 301}] WITH THE CONSTRAINT i + j + k = p It is the constraint which puzzles me. I would also like to plot all these Lists on one graph (using ListPlot?). I managed to do something like this for a table with two indices using a Do loop, but for three indices, it seems I would have to use a double loop and I don't know how to do that. Looking forward to any suggestions! ================= 1 You might want to look at either of FrobeniusSolve[] or IntegerPartitions[] for generating the indices that can be fed into m. – J. M.♦ Apr 22 '13 at 23:09 ================= 3 Answers 3 ================= You could list out the entire table then use GatherBy to reorganise it: gathered = GatherBy[Flatten[Table[ {i + j + k, m[[i, j, k]]}, {i, 100}, {j, 100}, {k, 100}], 2], First]; This gathers together all the elements where the first value (the sum of the indices) is the same. You'll have big lists around the sum of the average index value, and small ones at the extremes. ListPlot[Length /@ gathered] You can plot a particular list (say p = 150) with ListPlot[Last /@ gathered[[150]]]. But I don't have an interesting m to plot. this seems to work very well. Thanks a lot!!! – user7058 Apr 23 '13 at 12:17 How about this: tab = Cases[Flatten[Table[{p == i + j + k, 0.06 p, m[[i,j,k]]}, {i, 100}, {j, 100}, {k, 100}, {p, 2, 301}], 3], {True, __}][[;;,2;;]] Having Flattened the table before finding Cases you should be able to plot this directly. ListPlot[tab] In my opinion, the new table should have the same dimension as m, since every i,j,k in the range of 1 to 100 satisfy the relationship 2

True]