Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: create a table using .txt file
Date: Sun, 23 Nov 2008 20:04:02 +0000 (UTC)
Organization: Pierburg GmbH
Lines: 28
Message-ID: <ggccvh$8mt$1@fred.mathworks.com>
References: <ggcaq6$h65$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227470642 8925 172.30.248.38 (23 Nov 2008 20:04:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 23 Nov 2008 20:04:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 872224
Xref: news.mathworks.com comp.soft-sys.matlab:502670


"ashish " <ashishtx@hotmail.com> wrote in message <ggcaq6$h65$1@fred.mathworks.com>...
> I have loaded .txt file and stored it in a variable. How do i create a table using that data? I need to label each column and give it a title. 

By "table" you mean a new file? Then just use fprintf.

d = [1732 2 22
1777 12 15
1778 1 20
1564 4 23
1592 2 21
1592 4 2
2000 2 1
2008 11 3
2009 1 15];

titles = '"Title1","Title2","Title3"';

% write to file with pc type line breaks ('\r\n'):
fid = fopen('c:\mytable.csv','w');
fprintf(fid, '%s\r\n', titles);
fprintf(fid, '%f,%f,%f\r\n', d);
fclose(fid)


Such a csv file should open correctly in standard spreadsheet software, like OpenOffice. If it is MS Excel, of course, you may look at xlswrite and use a single cell array.

Regards
Andres