help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple advice needed on input and output


From: Nicholas Jankowski
Subject: Re: simple advice needed on input and output
Date: Mon, 25 Jun 2012 09:08:00 -0400

On Mon, Jun 25, 2012 at 2:03 AM, vilsu <address@hidden> wrote:
> Thank you for your reply!
>
> The file to be processed is like this:
>
> A * U * R * O * R
> A * U * R * O * U
> A * U * R * O * O
> .
> .
>
> the first A is a vector, the rest are matrices. The vector and matrices I
> know how to define to octave. Each line above I need to be calculated.
> Matrices are sparse, but seems that they would be faster to be calculated as
> normal matrices.
>
> I would like to have the results to a separate file, looking like this:
>
> [a1, a2, a3, a4, a5, a6]
> [a1, a2, a4, a3, a5, a6]
> .
> .
>
> That is it! Simple file in, simple file out. But I got into trouble trying
> to figure out all the details. There seems to be so much unspoken things,
> which are supposed to be genereal knowledge. Something like scripts and
> strings. I could figure that out.
>
> So I beg, I bow, humbly, ask for help. Thank you a lot!
>
> Yours, Vilsu
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/simple-advice-needed-on-input-and-output-tp4630909p4630925.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave

ok, where are A, U, R, O, and R defined? In the file, or manually by
you outside of the file?

At its simplest form a script is just a list of the same commands you
can type at the command line. It also allows for some programming
constructs like for loops, if-else statements, etc. Sounds like what
you want could be done with a for loop that reads in each line of the
text file one at a time and processes the line as a command. as is,
your text file could work as a script, (octave will execute A*U*R*O*R
as long as you've defined those previously) but there's nothing there
to control execution or save the output.

e.g.
octave:14> A = [1 2; 3,4]; U = A; R = A; O = A;
octave:15> line1 = A * U * R * O * O
line1 =

   1069   1558
   2337   3406

to individually read each line from the text file, execute it, and
then save it to a separate file, you'll probably want to handle each
line within a loop of some kind.  I recommend the following sections
of the Octave manual:

"10 Statements", for the do-while, for loops, and other program flow commands
"14.2.3 Line-Oriented Input", for fopen and fgetl, to get your file
read in as strings
"9 Evaluation" and the eval(string) command to execute strings as if
they were typed commands,
finally "14.1.3 Simple File I/O" for the save command to write your
data back to a file.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]