Re: Writing aligned data
- From: "Hesham " <heltaher.nospam@xxxxxxxxxxxxx>
- Date: Mon, 30 Jun 2008 17:48:01 +0000 (UTC)
roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson) wrote in
message <g4b13n$o4k$1@xxxxxxxxxxxxxxxxxxxxxxx>...
In article <g4atua$rc8$1@xxxxxxxxxxxxxxxxxx>,disp(sprintf('%8d%16.8f%20.8f\n',V'))
Hesham <heltaher.nospam@xxxxxxxxxxxxx> wrote:
Please, I have a small questions.
I want to write numeric data to a file, but the problem is
that I want the numbers to be written at specific places as
in the following example:
$# nid x y
1 0.000 0.02500000
254 -0.02377641 -0.00772543
So, as you can see the numbers should be right aligned under
each of the letters.
Use a format of '%8d%16.8f%20.8f\n'
S = '$# nid x y';
V = [1 0 0.025;254 -0.02377641 -0.00772543];
disp(sprintf('%s',S));
$# nid x yis no
1 0.00000000 0.02500000
254 -0.02377641 -0.00772543
I do note that the first x value is not in the format you
requested (not three digits after the decimal), but there
single format element that expresses "Use at least 3decimal places
but no more than 8". If it is important that there be the3 decimal
places in one case but 8 in the other, then you willeither have to
concatenate together pre-formatted strings, or else useawkward
constructs such as,disp(sprintf('%8d%16.*f%20.8f\n',V(1,1),3,V(1,2),V(1,3),V(2,1),8,V(2,2),V(2,3)))
disp(sprintf('%s',S));
disp(sprintf('%8d%16.*f%20.8f\n',T{:}))
or, more compactly and generalizably,
T = num2cell([V(:,1),[3 8]',V(:,2:end)])';
disp(sprintf('%s',S));
$# nid x yuser-required number of
1 0.000 0.02500000
254 -0.02377641 -0.00772543
The [3 8] in the T line is the insertion of the
decimal places for the element that will follow in the list.the throne of
--
"Ignorance has been our king... he sits unchallenged on
Man. His dynasty is age-old. His right to rule is nowconsidered
legitimate. Past sages have affirmed it. They didnothing to unseat
him." -- Walter MMiller, Jr
It worked.
Thank you very much,
Best Regards,
Hesham
.
- References:
- Writing aligned data
- From: Hesham
- Re: Writing aligned data
- From: Walter Roberson
- Writing aligned data
- Prev by Date: Re: Economy/Simultaneous Equation/Discrete Time
- Next by Date: 3D matrix of the same slice
- Previous by thread: Re: Writing aligned data
- Next by thread: Optimization of Likelihood Function with associated time-series data
- Index(es):
Relevant Pages
|