Thread Subject: Save vector in non-power notation

Subject: Save vector in non-power notation

From: Ida Haggstrom

Date: 30 Oct, 2009 14:34:01

Message: 1 of 5

Hi!

I have a 100x1 vector with values ranging from 0 to 10000. I want to save this vector as a text file, i.e.

>> save('filename.dat', 'myVector', '-ascii');

When I do this, the individual posts are saved in scientific power notation however, so my "filename.dat" looks like:

1.00000e+001
2.00000e+002
1.00000e+003
etc

My application requires it in "normal" format, i.e.

10.0000
200.0000
1000.0000
etc

How can I save my vectors in this notation instead?? It doesn't work to simply change to "format long g" in the terminal... thanks!
Ida

Subject: Save vector in non-power notation

From: Steven Lord

Date: 30 Oct, 2009 14:52:04

Message: 2 of 5


"Ida Haggstrom" <ida_haggstrom@yahoo.se> wrote in message
news:hcetgp$c0v$1@fred.mathworks.com...
> Hi!
>
> I have a 100x1 vector with values ranging from 0 to 10000. I want to save
> this vector as a text file, i.e.
>
>>> save('filename.dat', 'myVector', '-ascii');
>
> When I do this, the individual posts are saved in scientific power
> notation however, so my "filename.dat" looks like:
>
> 1.00000e+001
> 2.00000e+002
> 1.00000e+003
> etc
>
> My application requires it in "normal" format, i.e.
>
> 10.0000
> 200.0000
> 1000.0000
> etc
>
> How can I save my vectors in this notation instead?? It doesn't work to
> simply change to "format long g" in the terminal... thanks!

That's correct; FORMAT changes ONLY the way the matrix is displayed in the
command window, not how it is written to file or used in computations.

For this you will need to use a different file I/O function, like DLMWRITE
or the low-level combo of FOPEN/FPRINTF/FCLOSE (which will allow you to
control explicitly the format you use as part of the FPRINTF call.)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Save vector in non-power notation

From: Loren Shure

Date: 30 Oct, 2009 14:57:30

Message: 3 of 5

In article <hcetgp$c0v$1@fred.mathworks.com>, ida_haggstrom@yahoo.se
says...
> Hi!
>
> I have a 100x1 vector with values ranging from 0 to 10000. I want to save this vector as a text file, i.e.
>
> >> save('filename.dat', 'myVector', '-ascii');
>
> When I do this, the individual posts are saved in scientific power notation however, so my "filename.dat" looks like:
>
> 1.00000e+001
> 2.00000e+002
> 1.00000e+003
> etc
>
> My application requires it in "normal" format, i.e.
>
> 10.0000
> 200.0000
> 1000.0000
> etc
>
> How can I save my vectors in this notation instead?? It doesn't work to simply change to "format long g" in the terminal... thanks!
> Ida
>

Check out format and the options to the save function. If those don't
help, check out fprintf - you may have to write it yourself instead of
using save.


--
Loren
http://blogs.mathworks.com/loren

Subject: Save vector in non-power notation

From: Ida Haggstrom

Date: 3 Nov, 2009 09:50:04

Message: 4 of 5

Hello Steven and thanks for your reply!

DLMWRITE seems to do the trick, so I'll stick to that... =) Thanks for the tip!
/Ida

"Steven Lord" <slord@mathworks.com> wrote in message <hceuh1$etg$1@fred.mathworks.com>...
>
> "Ida Haggstrom" <ida_haggstrom@yahoo.se> wrote in message
> news:hcetgp$c0v$1@fred.mathworks.com...
> > Hi!
> >
> > I have a 100x1 vector with values ranging from 0 to 10000. I want to save
> > this vector as a text file, i.e.
> >
> >>> save('filename.dat', 'myVector', '-ascii');
> >
> > When I do this, the individual posts are saved in scientific power
> > notation however, so my "filename.dat" looks like:
> >
> > 1.00000e+001
> > 2.00000e+002
> > 1.00000e+003
> > etc
> >
> > My application requires it in "normal" format, i.e.
> >
> > 10.0000
> > 200.0000
> > 1000.0000
> > etc
> >
> > How can I save my vectors in this notation instead?? It doesn't work to
> > simply change to "format long g" in the terminal... thanks!
>
> That's correct; FORMAT changes ONLY the way the matrix is displayed in the
> command window, not how it is written to file or used in computations.
>
> For this you will need to use a different file I/O function, like DLMWRITE
> or the low-level combo of FOPEN/FPRINTF/FCLOSE (which will allow you to
> control explicitly the format you use as part of the FPRINTF call.)
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Subject: Save vector in non-power notation

From: Ida Haggstrom

Date: 3 Nov, 2009 10:14:02

Message: 5 of 5

Hello Steven and thanks for your reply!

DLMWRITE seems to do the trick, so I'll stick to that... =) Thanks for the tip!
/Ida

"Steven Lord" <slord@mathworks.com> wrote in message <hceuh1$etg$1@fred.mathworks.com>...
>
> "Ida Haggstrom" <ida_haggstrom@yahoo.se> wrote in message
> news:hcetgp$c0v$1@fred.mathworks.com...
> > Hi!
> >
> > I have a 100x1 vector with values ranging from 0 to 10000. I want to save
> > this vector as a text file, i.e.
> >
> >>> save('filename.dat', 'myVector', '-ascii');
> >
> > When I do this, the individual posts are saved in scientific power
> > notation however, so my "filename.dat" looks like:
> >
> > 1.00000e+001
> > 2.00000e+002
> > 1.00000e+003
> > etc
> >
> > My application requires it in "normal" format, i.e.
> >
> > 10.0000
> > 200.0000
> > 1000.0000
> > etc
> >
> > How can I save my vectors in this notation instead?? It doesn't work to
> > simply change to "format long g" in the terminal... thanks!
>
> That's correct; FORMAT changes ONLY the way the matrix is displayed in the
> command window, not how it is written to file or used in computations.
>
> For this you will need to use a different file I/O function, like DLMWRITE
> or the low-level combo of FOPEN/FPRINTF/FCLOSE (which will allow you to
> control explicitly the format you use as part of the FPRINTF call.)
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
save format Ida Haggstrom 30 Oct, 2009 10:34:03
rssFeed for this Thread

Contact us at files@mathworks.com