×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

save number as 999999 instead of 9.9999900e+005

save number as 999999 instead of 9.9999900e+005

save number as 999999 instead of 9.9999900e+005

(OP)
Hello,

I am trying to export (save, write, ...?) a vector from Matlab, so I can open it in an editor (PFE). (I am using Matlab to manipulate data). Saving the file works fine but when I open the file in an editor the figures are shown as 9.9999900e+005 instead of 999999.

Is there any command that tells Matlab to save (write, ...) the figures as 999999 (instead of 9.9999900e+005)?

So far I've tried
- save file.txt file -ascii and
- dlmwrite ('file.txt', file, '9')
but there might be another command?

Thanks for your help!
Kerstin

RE: save number as 999999 instead of 9.9999900e+005

Try using fprintf() to write your data.  Use the %f format specifer.

RE: save number as 999999 instead of 9.9999900e+005

%.0d may be better if you do not want anything after the decimal point.

M

--
Dr Michael F Platten

RE: save number as 999999 instead of 9.9999900e+005

(OP)
Thanks for your quick replies!

Unfortunately I am new to Matlab and don't understand the fprintf command very well... I used fprintf ('%7.4f\n', filename) which rewrote my vector in the format I am looking for, but it seems like I didn't save it at the same time. Can I use fprintf to set the format and save it at the same time (i.e. have a file that I can open in an editor)? If so, how would the command look like?

At the moment I am only working with a vector, but later I'll have to export matrices too. Can I use fprintf in this case too?

Thanks again for your help! I really appreciate it.

RE: save number as 999999 instead of 9.9999900e+005

you need to use the "fopen" command to create the file first

A = %vector to write to file%

filevar = fopen('testfile.txt','w')
fprintf(filevar, '%7.4f\n', A)
fclose(filever)

M

--
Dr Michael F Platten

RE: save number as 999999 instead of 9.9999900e+005

(OP)
Thank you so much smile

RE: save number as 999999 instead of 9.9999900e+005

(OP)
It seems as soon as one question is answered another one arises...

I am having a matrix with three columns (and lots of rows) and would like to create a text file in a special format.

Using fprintf has solved my formatting problem and it is now like I want it. But... in my txt file the colums are written one below the other instead of being next to each other,
i.e. it should be 1  2  3 but it is
1
2
3

I used the following command:

A = matrixVariableInMatlabWithThreeColumns;
fid = fopen ('matrix.txt','w');
fprintf(fid,'%7.0d %7.0d %13.6f\n',A);
fclose(fid)

Could anyone tell me what I need to change in my commands to ensure that the colums are written next to each other (i.e. as a matrix)? I've tried so many different commands but non seems to be the right one.

Thanks a lot!!!

RE: save number as 999999 instead of 9.9999900e+005

Have you tried transposing the matrix A?

M

--
Dr Michael F Platten

RE: save number as 999999 instead of 9.9999900e+005

(OP)
Hi!

No, I haven't. But thinking about it, I realised I might have explained my problem incorrectly.

My matrix looks actually like this:

531  531  1.00
531  532  5.000
531  533  17.000
531  534  2.000

while the txt file looks like this:
531
531
531
531
531
532
533
534
1.000
5.000
17.000
2.000

It seems I need to define somewhere that the columns should be printed next to each other (in a matrix format?), but I can't find a suitable command.
I am also not quite sure if I need to tell Matlab that the variable is a matrix and that it should thus write a matrix. Or if it knows that is given a matrix (I suppose so) but that I need to tell it specifically that it should write a matrix too?

Thanks for your help!

RE: save number as 999999 instead of 9.9999900e+005

Works for me:

>> a=magic(3);
>> fid=fopen('out','w');
>> fprintf(fid,'%.0f %.0f %.0f\n',a);
>> fclose(fid);
>> !more out
8 3 4
1 5 9
6 7 2

RE: save number as 999999 instead of 9.9999900e+005

(OP)
Thanks again! I finally understood transpose smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources