help-octave
[Top][All Lists]
Advanced

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

Re: Saving calculation answers to file


From: Juan Pablo Carbajal
Subject: Re: Saving calculation answers to file
Date: Tue, 24 Jul 2012 17:09:35 +0200

On Tue, Jul 24, 2012 at 4:35 PM, vilsu <address@hidden> wrote:
> Oh, and i will see that diary option. thanks for the hint.
>
> vilsu
>
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/Saving-calculation-answers-to-file-tp4631628p4631638.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

I can't really isolate what is your problem. As far as I can see you
already know how to evaluate each line in Octave, note that the lines
as they are won't be assigned to any matrix and therefore they won't
be saved. You need to store the result of each line in a variable and
then save this variable.
One possibility to do that is to change the text file keo. For example
you can store the result of each line in a cell

result{1} = A * U * r * U * r;
result{2} = A * U * r * U * s;
result{3} = A * U * r * U * l;

and so on, this will use memory (and you better preallocate the cell
"results") but at the end you can do

save results

To save your calculations. Also renaming keo to keo.m will allow you
to call it directly form the octave prompt

A question that is worth asking as this time is: Do the lines in keo
follow a pattern or rules? If the do then maybe you can program the
whole thing in Octave.

Finally, if you can't edit the file or write the program that generate
them in Octave, you will have to do the for loop suggested by vilsu
(note there was an error in his script, since at load time only the
last value will be recovered)

fid = fopen ("keo");
eof = fgetl (fid)
while eof != -1
      x = eval (eof);
      save -ascii -append out.txt x
      eof = fgetl (fid)
endwhile;
fclose (fid)

This can take a long time and all the results will be stored as a
single matrix, i.e. unless you know the size of each result you will
not know what part is the result of what line. To avoid that you could
store everything in a cell and save the cell at the end (I assume here
that N contains the number of lines in keo)

fid = fopen ("keo");
results = cell(N,1);
for i =1:N
      results{i} = eval (fgetl (fid));
endfor
save out.dat results
fclose (fid)

This last is similar to vilsu loop but every result is stored and then saved.

Well, let me know if any of your problems was addressed.

Cheers,
-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

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