Message Boards Message Boards

[✓] Output a Table as a Column?

GROUPS:

Hallo! I have a problem.

The code

Clear@"Global`*"     (*Speicher löschen*)

test1[k_] = k;
test2[n_] = n;
text = "abc";

myrow[y_] = y;
mycolumn[x_] = x; 
mycell[k_, n_] := 
 ToString@myrow[n] <> " " <> ToString@mycolumn[k] <> " " <> 
  ToString@test1[k] <> " " <> ToString@test2[n] <> " " <> 
  ToString@text 

list2 = Table[mycell[k, n], {k, 1, 2}, {n, 1, 3}]
Export["Test.txt", list2, "Table"]  

gives me a txt-file with

1 1 1 1 abc 2 1 1 2 abc 3 1 1 3 abc
1 2 2 1 abc 2 2 2 2 abc 3 2 2 3 abc

How can I export a textfile which contains the same stuff rowwise? That means:

1 1 1 1 abc
2 1 1 2 abc
3 1 1 3 abc
1 2 2 1 abc
2 2 2 2 abc
3 2 2 3 abc

Do you have any idea? Thanks a lot!

POSTED BY: cis cis
Answer
4 months ago

You can use Flatten:

Export["Test.txt", list2 // Flatten, "Table"]
POSTED BY: Gianluca Gorni
Answer
4 months ago

Group Abstract Group Abstract