0
$\begingroup$

I have created a table, and I want the variables that run through to create it, as the headings in their respective place.

So when my table is created by variable a and b, each going from 1 to 10 with step 1, I would like to get the table in a form that horizontal I have a and vertical I have b, and the values put in in their correct place.

Is there a way to achive that?

$\endgroup$
1
$\begingroup$
TableForm[Table[f[a, b], {a, 10}, {b, 10}], 
          TableHeadings -> {Range[10], Range[10]}, TableSpacing -> {1, 1}]

enter image description here

That's just the simplest 10-by-10 example, which is what the original question asked. Here's something close to what the first comment below asks for:

TableForm[Table[f[a, b], {a, 3, 30, 3}, {b, 60, 100, 10}],
          TableHeadings -> {Range[3, 30, 3], Range[60, 100, 10]}, TableSpacing->{1, 1}]

enter image description here

The form inside the table is just to indicate that whatever actual function you might use. For example:

f[x_, y_] := N[Sin[x] Log[y]]
TableForm[Table[f[a, b], {a, 3, 30, 3}, {b, 60, 100, 10}], 
          TableHeadings -> {Range[3, 30, 3], Range[60, 100, 10]}, 
          TableSpacing -> {1, 1}, TableAlignments -> "."]

enter image description here

If this is not the sort of display you're trying to obtain, then you'll have to explain in greater detail, and with a specific example of the desired output.

$\endgroup$
  • $\begingroup$ Sorry, i dont understand :( For example my A goes from 3 to 30 in steps of 3 and my b goes from 60 to 100 or something. I dont want to get the numbers displayed 1,2,3,4, i just want the values that goes into the calculation at that spot to be the headings. $\endgroup$ – Stephan Ketterer Sep 30 '14 at 14:51
0
$\begingroup$

When you create a table or matrix using the Table command, you want the variable that goes with the rows to come first, and the variable for the columns to come second.

mytable = Table[f[a, b], {a, 1, 10}, {b, 1, 10}];

Then to view the results in a visually pleasing manner, use TableForm

mytable // TableForm

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.