0
$\begingroup$

I have the following txt file and want to import it as 18 points in Mathematica, so that I can draw the points on a complex plane. Each line (except for the first line 100 and blank line) in the txt file is a point with its real and imaginary parts. For example, the points presented in the file are

$(1.004786849932060e-01+i*1.093556972652714e+00),(-1.004786849932060e-01+i*-1.093556972652714e+00), (9.976096134274947e-20+i*-1.192941404973469e-19), (-1.480297485865874e+00+i*7.422776004582909e-02),...$

100

1.004786849932060e-01 1.093556972652714e+00
-1.004786849932060e-01 -1.093556972652714e+00
9.976096134274947e-20 -1.192941404973469e-19
-1.480297485865874e+00 7.422776004582909e-02
-1.480297485865874e+00 7.422776004582909e-02
-1.000000000000000e+00 -5.551115123125783e-17

-8.393828623433014e-01 -8.910743549375130e-02
8.393828623433014e-01 8.910743549375130e-02
-2.564013936414357e-21 -4.714327574115172e-23
5.664048419599507e-01 -1.320526392429827e-01
5.664048419599508e-01 -1.320526392429827e-01
-1.000000000000000e+00 0.000000000000000e+00

-1.182775851427075e+00 2.322257341019021e+00
1.182775851427075e+00 -2.322257341019021e+00
5.693577648965902e-20 -1.430540343549141e-19
-2.491786138158304e+00 -1.102305635983134e+00
-2.491786138158304e+00 -1.102305635983134e+00
-1.000000000000000e+00 0.000000000000000e+00

Could anyone help?

Thank you a lot!

Moreover, is it possible to draw the points with 6 different color (if the point is in the first line of a block, then we use red; if the point is in the second line, then we use yellow,....)

$\endgroup$

1 Answer 1

3
$\begingroup$
data = ReadList["C:/test.txt", Number] // Rest // Partition[#, 2] & //
    Complex @@@ # & // Chop
{0.100479 + 1.09356 I, -0.100479 - 1.09356 I, 0, -1.4803 + 
  0.0742278 I, -1.4803 + 0.0742278 I, -1., -0.839383 - 0.0891074 I, 
 0.839383 + 0.0891074 I, 0, 0.566405 - 0.132053 I, 
 0.566405 - 0.132053 I, -1., -1.18278 + 2.32226 I, 
 1.18278 - 2.32226 I, 0, -2.49179 - 1.10231 I, -2.49179 - 
  1.10231 I, -1.}
ComplexListPlot[data, PlotStyle -> {AbsolutePointSize[6], Red}]

enter image description here

$\endgroup$
5
  • $\begingroup$ Thank you so much! $\endgroup$
    – M.K
    Mar 13, 2022 at 15:06
  • 1
    $\begingroup$ My pleasure, thanks for the accept. If there is one number per line (and missing either real or complex part), then explore ReadLine in conjunction with Interpreter. $\endgroup$
    – Syed
    Mar 13, 2022 at 15:15
  • $\begingroup$ thanks!! is it possible to draw the points with 6 different color (if the point is in the first line of a block, then we use red; if the point is in the second line, then we use yellow,....)? should I open a new question or just update this one? $\endgroup$
    – M.K
    Mar 13, 2022 at 15:26
  • 1
    $\begingroup$ dataColored = Transpose[Partition[data, 6]] and ComplexListPlot[dataColored, PlotStyle -> {Red, Orange, Blue, Green, Purple, Cyan}] ? $\endgroup$
    – Syed
    Mar 13, 2022 at 15:31
  • $\begingroup$ Thanks a lot!!! $\endgroup$
    – M.K
    Mar 13, 2022 at 15:41

Your Answer

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

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