Path: news.mathworks.com!not-for-mail
From: "Shanmugam Kannappan" <shanmugambe@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: dlmwrite
Date: Tue, 9 Sep 2008 06:02:06 +0000 (UTC)
Organization: NFIndia
Lines: 69
Message-ID: <ga53gu$sr7$1@fred.mathworks.com>
References: <ga4rli$s9v$1@fred.mathworks.com>
Reply-To: "Shanmugam Kannappan" <shanmugambe@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1220940126 29543 172.30.248.37 (9 Sep 2008 06:02:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 9 Sep 2008 06:02:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1441885
Xref: news.mathworks.com comp.soft-sys.matlab:489316



Hello Sir/Madam,

You can do this operation by the folloing code.

%% This part will do the first operation
fp=fopen('a.txt','w+');
fprintf(fp,'Jo 9\nTom 10\nJon\nTim 12\n')
fclose(fp)
%upto this u will have three rows only.
%% U can append the data's to the existing file(a.txt)
% by this code 
fp=fopen('a.txt','a+');
fprintf(fp,'Henry 34\nBob 3\nJim\n')
fclose(fp)
% finaly u will get the txt file with all the strings in 
% Order
open('a.txt')

Regards
Shanmugam.K

"Jessica " <jyorzinski@ucdavis.edu> wrote in message <ga4rli$s9v$1@fred.mathworks.com>...
> Hi,
> 
> I'm trying to append words onto a preexisting .txt file. For example, my original a.txt file:
> 
> Jo  9
> Tom 10
> Jon 
> Tim 12
> 
> And I want to append these values:
> 
> ntxt={
> 'Henry 34'
> 'Bob 3'
> 'Jim '
> }
> 
> so that it produces:
> 
> Jo  9
> Tom 10
> Jon 
> Tim 12
> Henry 34
> Bob 3
> Jim 
> 
> I have tried the code:
> 
> s=textread(a,'%s', 'delimiter','\n','whitespace','');
> Final=[s;ntxt];
> dlmwrite(fnam,char(Final), 'delimiter', '');
> 
> However, this gives me very strange formating. I need the txt file to have things listed like:
> 
> Jo  9
> Tom 10
> Jon 
> Tim 12
> Henry 34
> Bob 3
> Jim 
> 
> Any suggestions?
> 
> Thanks!