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!

*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

mixing fprintf and dlmwrite line position error?

mixing fprintf and dlmwrite line position error?

mixing fprintf and dlmwrite line position error?

Hello, everyone! Just a quick question. Here is some code:

fprintf(fid, '# BEGIN OUTPUT r (submodular) matrix\n');
dlmwrite('bdc', r, '-append', 'delimiter', '\t');
fprintf(fid, '# END OUTPUT r matrix\n');

fprintf(fid, '# BEGIN OUTPUT mother matrix\n');
dlmwrite('bdc', mother, '-append', 'delimiter', '\t');
fprintf(fid, '# END OUTPUT mother matrix\n');

Unfortuneatly, this code prints out:

# BEGIN OUTPUT r (submodular) matrix
# END OUTPUT r matrix
# BEGIN OUTPUT mother matrix
# END OUTPUT mother matrix
.... (data of r matrix and then mother matrix)

I'm not sure what is happening here... any ideas? dlmwrite doesn't lock until it finishes? dlmwrite does not transfer the file position information to the file handle?

Any ideas? This is just curious! Thank you!



RE: mixing fprintf and dlmwrite line position error?

It smells like Matlab has a cached file pointer for fprintf() and is reopening the file for each dlmwrite(), so the outputs aren't necessarily sequenced correctly (multiple file pointers).  You may want to try closing the file before dlmwrite() so it flushes and then reopening it after.

You may find an answer in here somewhere.  TMW's "solution" pages are generally very good - I always learn something new from them.


- Steve

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! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close