1
$\begingroup$

I have a *.txt file with values like so:

0 2 4 3 4 2

the position in this huge *.txt corresponds to the x and y coordinates of the value (in the text file). For example that 0 has coordinates {0, 0}, the 2 has coordinates {0, 1} and so on. After the
{0, 1000} comes the value with {1, 0} coordinates.

I just need to import this file and later on re-use it.

$\endgroup$
0

1 Answer 1

3
$\begingroup$

Some fake data:

faketxtdata=StringJoin@@Table[ToString[RandomInteger[{0,10}]]<>"  ",{10201}];

The first 20 characters of the data:

StringTake[faketxtdata,20]
(* 9  10  2  4  10  10   *)

The file fakedata.txt contains a single string:

Export["fakedata.txt",faketxtdata];

Using "Words" as the second argument of Import, imports

words separated by spaces, given as a list of strings.

imp=Import["fakedata.txt", "Words"];

And ... a possible interpretation of

Plot data from txt

and

I need to make a density plot

in OP's original post:

MatrixPlot[Partition[ToExpression/@imp,101],DataRange->{{0,100},{0,100}},ImageSize->600]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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