I have got a $1000\times 4$ matrix of data in .txt form. Rows are seperated with blank spaces and not with commas. I want to plot the second column against the first one (they correspond to y(x) and x respectively).

This is part of the matrix

 0.000000000000000E+00    1.000000000000000E+00    1.000000000000000E+00    5.000000000000000E-01
 9.999999747378752E-06    9.999950000251270E-01    1.000006666744476E+00    5.000083332845139E-01
 1.999999949475750E-05    9.999900001002581E-01    1.000013333644511E+00    5.000166664718175E-01
 2.999999924213625E-05    9.999850002253973E-01    1.000020000700112E+00    5.000249995619233E-01
 3.999999898951501E-05    9.999800004005488E-01    1.000026667911283E+00    5.000333325548432E-01
 4.999999873689376E-05    9.999750006257166E-01    1.000033335278029E+00    5.000416654505894E-01
 5.999999848427251E-05    9.999700009009049E-01    1.000040002800354E+00    5.000499982491741E-01
 6.999999823165126E-05    9.999650012261176E-01    1.000046670478263E+00    5.000583309506094E-01
 7.999999797903001E-05    9.999600016013590E-01    1.000053338311761E+00    5.000666635549075E-01
 8.999999772640876E-05    9.999550020266330E-01    1.000060006300853E+00    5.000749960620804E-01
 9.999999747378752E-05    9.999500025019438E-01    1.000066674445544E+00    5.000833284721403E-01
 1.099999972211663E-04    9.999450030272953E-01    1.000073342745837E+00    5.000916607850994E-01
 1.199999969685450E-04    9.999400036026918E-01    1.000080011201739E+00    5.000999930009696E-01
 1.299999967159238E-04    9.999350042281372E-01    1.000086679813254E+00    5.001083251197633E-01
 1.399999964633025E-04    9.999300049036357E-01    1.000093348580387E+00    5.001166571414926E-01
 1.499999962106813E-04    9.999250056291913E-01    1.000100017503142E+00    5.001249890661694E-01
 1.599999959580600E-04    9.999200064048082E-01    1.000106686581524E+00    5.001333208938060E-01
 1.699999957054388E-04    9.999150072304903E-01    1.000113355815538E+00    5.001416526244146E-01
 1.799999954528175E-04    9.999100081062419E-01    1.000120025205189E+00    5.001499842580072E-01
 1.899999952001963E-04    9.999050090320668E-01    1.000126694750482E+00    5.001583157945959E-01

I tried

data = Import["C:/mydata.txt", "TSV"];
ListPlot[data[[All, 1 ;; 2]]]

and it did not work.

Can anyone help?

PS: If I could insert commas between elements in each row, then I would be able to plot according to this answer.

  • $\begingroup$ …I mean the text of the matrix, not the screenshot. $\endgroup$ – xzczd Sep 17 '19 at 11:01
  • $\begingroup$ When I try to paste the text of the matrix everything comes in the same line: `\` does not seem to work. $\endgroup$ – user67126 Sep 17 '19 at 11:05
  • $\begingroup$ Then are you sure it's a 1000*4 matrix? Can it be a 1*4000 "matrix"? What if you adjust the width of the text editor? $\endgroup$ – xzczd Sep 17 '19 at 11:08

Suppose is the path to the file (You can easily obtain the path by Ctrl+c and Ctrl+v on Windows ) then:

Import[…, "Table"]


ReadList[…, Real, RecordLists -> True]

The latter should be faster.

| improve this answer | |
  • $\begingroup$ Probably you mean " is the path to the file", not "directory of the file". $\endgroup$ – Alexey Popkov Sep 18 '19 at 3:12
  • $\begingroup$ @AlexeyPopkov ? (Googling… ) Oops… yeah I mean path, corrected, thx for pointing out. $\endgroup$ – xzczd Sep 18 '19 at 5:56

Your Answer

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