I'm new here and with Mathematica, too. I want Mathematica to import data from a txt file (it has one column of data). These entries are z-values. From this I want to make a matrix - 508 entries make one row, 308 rows in total. And then I want to export it to a dat file.
Here is my code:
data = Import["D:\\Data\\Mathematica\\Convert_data\\rawdata.txt", "Table"]; Flatten[data];
carray = ConstantArray[1, {308, 508}];
For[j = 1, j < 309, j++,
For[i = 1, i < 508, i++, carray[[j, i]] = data[[(j - 1)*508 + i]] ]
];
Export["test.dat", carray, "Table"]
It does nearly everything it is supposed to do. It creates a matrix as I want it to, but all the entries are in curly braces. I think the problem is right at the beginning, when I import the data, all the entries are in a curly brace, and all these braces are within a common brace. I tried to get rid of the single curly braces around each value with "Flatten", but it doesn't do anything.
The txt file I start with looks like this:
1.598669e+000
1.570571e+000
1.600274e+000
1.513271e+000
1.549999e+000
1.426268e+000
1.197772e+000
....
It has many entries, so I don't show all of them here.
Flatten[data]
does nothing. (It creates a flat version ofdata
and discards it). You would needdata=Flatten[data]
to do what you probably though you were doing. $\endgroup$