Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski 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
Joined
May 6, 2009
Messages
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


 
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