From: ben harper on
"Edward D." <edwardawsremove.this(a)gmail.com> wrote in message <hjdd2h$pon$1(a)fred.mathworks.com>...
> Walter Roberson <roberson(a)hushmail.com> wrote in message <hjdbri$3g0$1(a)canopus.cc.umanitoba.ca>...
> > ben harper wrote:
> >
> > > when i make
> > >
> > > variable1 =
> > > 1.0e+003 *
> > > 0.3000 9.3000 -0.0063 9.3063
> > > sprintf('%6.1f',variable1)
> >
> > > the answer is
> > > ans =
> > > 300.09300.0 -6.39306.3
> >
> > > is it possible to show in vector/matrix form?
> >
> > sprintf([repmat('%6.1f ',1,length(variable1)-1), '%6.1f'], variable1)
> >
> > Notice the space after the f and before the quote in the first instance of %6.1 .
> >
> > If you do not mind there being a trailing space at the end of the line, you
> > can simplify the whole thing to
> >
> > sprintf('%6.1f ', variable1)
>
> ------------------
> format short g
>
> will do the trick i believe

Thank you all, for your help.

format short g is ok.
From: ben harper on
is it possible to write the variables to text file in the format of short g with save command?
(short g: Best of fixed or floating point, with 4 digits after the decimal point. For example, 3.1416.)

I mean writing the values

0.0000000e+000 0.0000000e+000 -3.0000000e+002 5.0000000e+003

to the text file like
0 0 -300 5000

thank you
From: dpb on
ben harper wrote:
> is it possible to write the variables to text file in the format of
> short g with save command?
> (short g: Best of fixed or floating point, with 4 digits after the
> decimal point. For example, 3.1416.)
>
> I mean writing the values
>
> 0.0000000e+000 0.0000000e+000 -3.0000000e+002 5.0000000e+003
>
> to the text file like
> 0 0 -300 5000

You can use the '%g' format in s/fprintf() functions for chosen field
width/precision.

You're at the mercy of the rt i/o library (essentially C Standard rules)
for what the actual form of any particular value will be converted to.

--