[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to print long integers through Octave script in terminal?
From: |
Sebastian Schöps |
Subject: |
Re: How to print long integers through Octave script in terminal? |
Date: |
Tue, 3 Jun 2014 11:24:38 -0700 (PDT) |
> Well my script is extremely simple, I am trying to open a file with long
> values more than 6 digits after the decimal position. Sample of file:
[...]
> It only prints the first 6 digits after I want to print more than 6 like 15
> digits which is the max of a long format float.
>
> Well on matlab the syntax that I am using is:
>
> test_1 = importdata('output.txt');
> column_1 = test_1(:,5);
>
> Which extracts the 5th column of the *.txt file.
>
> So I am also wondering how can I do that on Octave, extract only the 5th
> column.
Dear Thanos,
it seems that you are confusing integers and floating point numbers. I guess
that you want to print long *floats*? But be warned, it is not wise to care
about the last digit of a very long floating point number. If you are not aware
of this please read e.g. http://en.wikipedia.org/wiki/Floating_point and maybe
http://en.wikipedia.org/wiki/Machine_epsilon before messing around with data.
To answer your question: I recommend to use "fprintf" as described at
http://www.gnu.org/software/octave/doc/interpreter/Formatted-Output.html
to format output. This gives more control than using "format long".
The following works in Octave and Matlab and should help you to get started
%-----
% read tabular data from file
table = load ('output.txt','-ascii');
% loop over all columns and print
for col=1:size(table,2)
fprintf('Column %d\n',col);
fprintf('%.6f\n',table(:,col));
end
%-----
Bye
Seb.
--
View this message in context:
http://octave.1599824.n4.nabble.com/How-to-print-long-integers-through-Octave-script-in-terminal-tp4664442p4664446.html
Sent from the Octave - General mailing list archive at Nabble.com.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: How to print long integers through Octave script in terminal?,
Sebastian Schöps <=