Message Boards Message Boards

0
|
9461 Views
|
6 Replies
|
1 Total Likes
View groups...
Share
Share this post:

[?] Read a text file in the Wolfram language?

Attachments:
POSTED BY: GABBAR JADAV
6 Replies

I added some numbers to your file. You presume they come in blocks of 4 so I created the file with 12 numbers.

v = Partition[ReadList["posit_1.txt"], 4]
(#[[1]] #[[4]] + #[[2]] #[[3]]) & /@ v

I Map a function where I switch the elements of each row I Map on to. The #[[1]] means the first item of the list so its the first * fourth + second * third.

Attachments:
POSTED BY: l van Veen

Gabbar,

You need to escape the backslashes and add the missing semicolons at the end of each command, or put your commands in multiple cells. In your code you are trying to extract elements from an undefined variable v.

After completing a tutorial like http://www.wolfram.com/language/fast-introduction-for-programmers/en/ everything will make sense.

Regards,

Gustavo

POSTED BY: Gustavo Delfino

Hello,

please any one help me in resolving the below issue

i have tried by changing by brackets in my code but its is not taking my input from text file to perform my arithmatic operation , please look in to my code and make necessary changes ,perform arithmatic operation for given text file inputs

Attachments:
POSTED BY: GABBAR JADAV

Grabbar,

You have a variety of issues in you question (missing brackets, incorrect calls to Take, referencing indices beyond the last value). Focus first on importing the data:

multilineString = Import["posit.txt", "Text"]

"64817367.784333

1234.566

2345.567

3456.890

123

234

456
"

Then split into lines:

listOfStrings = StringSplit[multilineString]

{"64817367.784333", "1234.566", "2345.567", "3456.890", "123", "234", "456"}

And convert the strings to numbers:

listOfNumbers = Map[ToExpression, listOfStrings]

{6.48174*10^7, 1234.57, 2345.57, 3456.89, 123, 234, 456}

After that you can use the Partition command to split the data in sets of 4 and then apply your formula.

POSTED BY: Gustavo Delfino
Attachments:
POSTED BY: GABBAR JADAV

Could you provide a sample "C:\work\posit.txt" ? You probably need to split your text into lines and pay attention to [ ] vs [[ ]]

POSTED BY: Gustavo Delfino
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract