Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

mixing fprintf and dlmwrite line position error?

Status
Not open for further replies.

susanex2texas

Computer
May 6, 2009
1
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


 
Replies continue below

Recommended for you

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top