Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello

How can i write to a text file every time start from the next line, for example say i have a text file "test.txt" and i have an iterative code that prints say "hello" what i want is hello to be print on next line every time like this

hello
hello
hello

so far i have used
 ta='text.txt';
fid = fopen((ta), 'a');
Loop{ fprintf(fid,'%s\n',word); }

any help is warmly appreciated.
Posted

1 solution

In my opinion your loop never ends... Why? Read more about loops: http://www.mathworks.com/help/search/doccenter/en/R2012b?qdoc=loops&submitsearch=Search[^]

If you would like to write the data at the end of existing file, read this: http://www.mathworks.com/help/matlab/import_export/writing-to-text-data-files-with-low-level-io.html#br5_kad-1[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Oct-12 14:30pm    
He-he, right, a 5. I'm just feel awkward to recommend anything in particular. With this level, I cannot be sure the whole thing makes sense.
--SA
Maciej Los 12-Oct-12 14:34pm    
;) Yes, it's true ;)
Thank you, Sergey.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900