I want to pick up some numbers from a text,such as file.txt .At the same time I set a(n) ,the range of n is from one to the largest number of the numbers ,and per a(n) equal one number of the text .for example a(1)=2,a(2)=4,a(3)=5,.........2,4,5 are the numbers from the file.txt
thanks for your interpretation!
How to pick up numbers from a text ?
Moderators: silvia, selimgunay, Moderators
Re: How to pick up numbers from a text ?
set inFile [open data.txt r]
set numbers [list]
while { [gets $inFile line] >= 0 } {
foreach word [split $line] {
lappend numbers $word
}
}
puts $numbers
note the list indexing starts at 0 and not 1
set numbers [list]
while { [gets $inFile line] >= 0 } {
foreach word [split $line] {
lappend numbers $word
}
}
puts $numbers
note the list indexing starts at 0 and not 1
Re: How to pick up numbers from a text ?
Thank you for answering. I have understood which you had provided to me .
But I expect to set a(n), such as
for {set n 1} {$n<=10} {incr n 1} {
set a([expr $n]) $numbers
puts "a([expr $n]):$a([expr $n])"
}
I would like to applicate a(n) to solve the problem .Such as d(n)=a(n)+n*n .
But I can't get the real result that I expect .IF I input these procedures into opensees
,I obtain a(1)=a(2)=..............=a(10)=all numbers from data.txt .Rather than a(1)=-1.4,a(2)=-10.8......a(10)=-8.5
here is the data.txt
"-1.4
-10.8
-10.1
-8.8
-9.5
-12
-14.2
-12.8
-11
-8.5"
Thank you again for answering
But I expect to set a(n), such as
for {set n 1} {$n<=10} {incr n 1} {
set a([expr $n]) $numbers
puts "a([expr $n]):$a([expr $n])"
}
I would like to applicate a(n) to solve the problem .Such as d(n)=a(n)+n*n .
But I can't get the real result that I expect .IF I input these procedures into opensees
,I obtain a(1)=a(2)=..............=a(10)=all numbers from data.txt .Rather than a(1)=-1.4,a(2)=-10.8......a(10)=-8.5
here is the data.txt
"-1.4
-10.8
-10.1
-8.8
-9.5
-12
-14.2
-12.8
-11
-8.5"
Thank you again for answering
Re: How to pick up numbers from a text ?
i have not a clue as to what you want to do. could you rephrase.
Re: How to pick up numbers from a text ?
Sorry ,I hadn't explained the problem clearly .
I want to use central difference method to resolve the Equation of Motion .a(n ) is earthquake acceleration
which is equal to numbers from data.txt. I must input one a(n) per step of numerical calculation .M is mass and -M*a(n)
as external force. I expect to know how to pick up numbers from data.txt . n is from 1 to the maximum of the numbers from data.txt.
Thank you very much
I want to use central difference method to resolve the Equation of Motion .a(n ) is earthquake acceleration
which is equal to numbers from data.txt. I must input one a(n) per step of numerical calculation .M is mass and -M*a(n)
as external force. I expect to know how to pick up numbers from data.txt . n is from 1 to the maximum of the numbers from data.txt.
Thank you very much