0
$\begingroup$

I've the following code:

Import["hoi1.txt"]

And it gives me:

"(time,voltage,current,power) (1,10,5,10*5) (2,20,6,20*6) (3,30,7,30*7) (4,40,8,40*8) (5,50,9,50*9) (6,60,10,60*10) (7,70,11,70*11) (8,80,12,80*12) (9,90,13,90*13) (10,100,14,100*14) (11,110,15,110*15) (12,120,16,120*16) (13,130,17,130*17) (14,140,18,140*18) (15,150,19,150*19) (16,160,20,160*20) (17,170,21,170*21) (18,180,22,180*22) (19,190,23,190*23)"

But I only want the time values $8,9,10$ how can I improve my code so that only those times are printed in my notebook?

$\endgroup$
  • $\begingroup$ Where did you get "lines" idea from? $\endgroup$ – Kuba Apr 30 '18 at 7:22
  • $\begingroup$ @Kuba From reference.wolfram.com/language/ref/format/Text.html but I noticed that I can also drop the "lines" and get the same (see the edit). $\endgroup$ – Looper Apr 30 '18 at 7:26
  • $\begingroup$ It is "Lines", isn't it? $\endgroup$ – Kuba Apr 30 '18 at 7:47
2
$\begingroup$

One way could be

s = Import["hoi1.txt"];
data = ToExpression@StringSplit[
    Rest[
     StringSplit[s, {"(", ") (", ")"}]
     ],
    ","];
Select[data, MemberQ[{8, 9, 10}, #[[1]]] &]
$\endgroup$

Your Answer

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

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