Thread Subject: create a table using .txt file

Subject: create a table using .txt file

From: ashish

Date: 23 Nov, 2008 19:27:02

Message: 1 of 3

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.
Below is the .txt data
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


Thank you.

Subject: create a table using .txt file

From: Walter Roberson

Date: 23 Nov, 2008 19:34:23

Message: 2 of 3

ashish wrote:
> 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.
> Below is the .txt data
> 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

Which version do you have? If you have R2008b, you can use the (newly official)
uitable(); you can probably use num2cell() to get the proper cell array to feed in.
(A usable uitable might also be in R2008a; before that I believe the uitable
was undocumented and had notable problems.)

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: create a table using .txt file

From: Andres

Date: 23 Nov, 2008 20:04:02

Message: 3 of 3

"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

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com