Click here to Skip to main content
11,709,536 members (46,103 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 11-Oct-12 23:50pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 590
1 OriginalGriff 250
2 Maciej Los 225
3 Peter Leow 219
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,027
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100