Creating a matrix of strings

  • Follow


How can I make a matrix whose entries are strings? This test did not
work:

M = ['Eccentricity (Largest Area)', 'Euler_Number (Largest Area)']

When I wrote this out as a CSV file (using csvwrite), it put each
letter in a column.

Thanks, Alan
0
Reply jalanthomas (125) 5/14/2007 9:19:40 PM

Yo can make a cell array.. write your strings like you would do to
create a nunber matrix, but inside { }, instead [ ]... strings
separeted by semi-colon will be put in rows, and separed by spaces, in
column
your test will work if you do that like:

M = {'Eccentricity (Largest Area)', 'Euler_Number (Largest Area)'}

Alan Thomas escreveu:

> How can I make a matrix whose entries are strings? This test did not
> work:
>
> M = ['Eccentricity (Largest Area)', 'Euler_Number (Largest Area)']
>
> When I wrote this out as a CSV file (using csvwrite), it put each
> letter in a column.
>
> Thanks, Alan

0
Reply ocerafa (1) 5/14/2007 9:57:11 PM


In article <ef56deb.-1@webcrossing.raydaftYaTP>,
Alan Thomas <jalanthomas@verizon.net> wrote:
>How can I make a matrix whose entries are strings? This test did not
>work:

>M = ['Eccentricity (Largest Area)', 'Euler_Number (Largest Area)']

M = ['Eccentricity (Largest Area)'; 'Euler_Number (Largest Area)']

Note that this only works because both happen to have exactly the
same length. If you want strings of different lengths, you
need to either blank pad or use a cell string array. The cell
string array is easier ;)
-- 
  Is there any thing whereof it may be said, See, this is new? It hath
  been already of old time, which was before us.       -- Ecclesiastes
0
Reply roberson2 (8067) 5/14/2007 10:06:48 PM

Actually, I got the same results. Is there something wrong with the
way I am writing it out? Here is the code:

M = {'Eccentricity (Largest Area)', 'Euler_Number (Largest Area)'}
csvwrite ('output.csv',M);

   The resulting CSV file again has one letter from the string in
each column.

Thanks, Alan

 Rafa wrote:
> your test will work if you do that like:
>
> M = {'Eccentricity (Largest Area)', 'Euler_Number (Largest Area)'}
>
0
Reply jalanthomas (125) 5/14/2007 10:07:10 PM

This does not seem to work either. I get:

E	c	c	e	n	t	r	i	c	i	t	y	 	(	L	a	r	g	e	s	t	 	A	r	e	a	)
E	u	l	e	r	_	N	u	m	b	e	r	 	(	L	a	r	g	e	s	t	 	A	r	e	a	)

in the first two rows of the CSV file. Thanks, Alan

 Walter Roberson wrote:
>
> M = ['Eccentricity (Largest Area)'; 'Euler_Number (Largest Area)']
>
0
Reply jalanthomas (125) 5/14/2007 10:16:10 PM

In article <ef56deb.3@webcrossing.raydaftYaTP>,
Alan  <jalanthomas@verizon.net> top-posted,

Top-posting makes it more difficult to follow discussions.

> Walter Roberson wrote:

>> M = ['Eccentricity (Largest Area)'; 'Euler_Number (Largest Area)']


>This does not seem to work either. I get:

>E	c	c	e	n	t	r	i	c	i	t	y	 	(	L	a	r	g	e	s	t	 	A	r	e	a	)
>E	u	l	e	r	_	N	u	m	b	e	r	 	(	L	a	r	g	e	s	t	 	A	r	e	a	)

>in the first two rows of the CSV file.

What do the spaces represent? Do they represent that each letter
was put into a different cell? Or do they represent that the lines
were written with some kind of UTF-8 encoding with alternating NULL
(binary 0) and letters?
-- 
Programming is what happens while you're busy making other plans.
0
Reply roberson2 (8067) 5/14/2007 10:30:20 PM

Alan Thomas wrote:
>
>
> How can I make a matrix whose entries are strings? This test did
> not
> work:
>
> M = ['Eccentricity (Largest Area)', 'Euler_Number (Largest Area)']
>
> When I wrote this out as a CSV file (using csvwrite), it put each
> letter in a column.
>
> Thanks, Alan
0
Reply jalanthomas (125) 5/14/2007 11:45:33 PM

Sorry. Don`t know what I just did.

   Each letter is still written to a separate cell.

Alan

Walter Roberson wrote:

>E c c e n t r i c i t y ( L a r g e s t A r e a )
>E u l e r _ N u m b e r ( L a r g e s t A r e a )

What do the spaces represent? Do they represent that each letter
was put into a different cell? Or do they represent that the lines
were written with some kind of UTF-8 encoding with alternating NULL
(binary 0) and letters?
0
Reply jalanthomas (125) 5/14/2007 11:56:28 PM

In article <ef56deb.-1@webcrossing.raydaftYaTP>,
Alan Thomas <jalanthomas@verizon.net> wrote:
>How can I make a matrix whose entries are strings? This test did not
>work:

>M = ['Eccentricity (Largest Area)', 'Euler_Number (Largest Area)']

>When I wrote this out as a CSV file (using csvwrite), it put each
>letter in a column.

csvwrite is not documented as being able to handle strings :(

You could try something like this,

>> dlmwrite('junk.csv',char({'"hello","there"';'"Alan"'}),'')
>> !cat junk.csv
"hello","there"
"Alan"         

That is, tell it to use the empty seperator between cells,
and put in the quotation marks and commas between cells yourself.
The shorter lines will be blank padded.
-- 
  Is there any thing whereof it may be said, See, this is new? It hath
  been already of old time, which was before us.       -- Ecclesiastes
0
Reply roberson2 (8067) 5/15/2007 4:07:30 PM

Walter,

    Thanks! This worked like a champ. Alan
0
Reply jalanthomas (125) 5/15/2007 5:30:18 PM

9 Replies
21 Views

(page loaded in 1.103 seconds)


Reply: