×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

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?

(OP)
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
2
.... (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!

Susan


 

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.

http://www.mathworks.com/support/product/solutions.html?show=yes&page=1&product=ML&type=Solution&category=1-15ESR&topic=Data%20Importing/Exporting&productcategory=1-1478S&subcategory=1-15ESR&parentcategory=1-15EQZ
 

- 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


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now