help-octave
[Top][All Lists]

## Re: Matrix of strings

 From: A. Scottedward Hodel Subject: Re: Matrix of strings Date: Fri, 12 Nov 1999 10:23:18 -0600 User-agent: Microsoft Outlook Express Macintosh Edition - 5.0 (1513)

```> on 11/12/99 9:43 AM, SZABO Sandor at address@hidden wrote:

>
>
> Date: Friday, November 12, 1999 9:30 AM
> Subject: Matrix of strings
>
> Hello everyone,
>
> I am a new octave user and I have a problem:
> I would like to create a 2 by 3 matrix A whose elements are "a", "bb",
> "ccc"; "d", "e", "f".
> Of course I would like to use the A(1,1) reference.
> Sandor

this is not possible with the matrix data type, since it requires a single
character in the each entry of A.

In Octave, you can create an array of strings with

A = str2mat("a","bb","ccc","d","e","f")
which returns
A =

a
bb
ccc
d
e
f

and
size(A)
ans =
6  3

You may alternatively create a list of string matrices: (2.1.x sources)

A = list( str2mat("a","d"), str2mat("bb","e"), str2mat("ccc","f"))
i = 2
j = 3

Then
nth(A,j)(i,:)
returns
ans = f
--
A S Hodel Assoc. Prof. Dept Elect and Computer Eng, Auburn Univ,AL
36849-5201
On leave at NASA Marshall Space Flight Center (256) 544-1426
Address until 31 July 2000:Mail Code TD-55, MSFC, Alabama, 35812
http://www.eng.auburn.edu/~scotte

-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------

```