Thread Subject: array of strings

Subject: array of strings

From: abdelmoumen

Date: 24 Nov, 2009 12:35:06

Message: 1 of 3

hi everybody

i want create an array of str like this:
array= ['str1' 'str2' ... 'strn']
but when i call array(1) i dont have the entire first
str but only the first character of the first str
for example:
>>myarray=['abc' 'def' 'gih'];
>>myarray(2)
        b %not 'def'
how i do that

Subject: array of strings

From: Branko

Date: 24 Nov, 2009 13:14:18

Message: 2 of 3

"abdelmoumen " <bmoumen27@yahoo.fr> wrote in message <hegjtq$9i5$1@fred.mathworks.com>...
> hi everybody
>
> i want create an array of str like this:
> array= ['str1' 'str2' ... 'strn']
> but when i call array(1) i dont have the entire first
> str but only the first character of the first str
> for example:
> >>myarray=['abc' 'def' 'gih'];
> >>myarray(2)
> b %not 'def'
> how i do that

You should you cell array:
myarray={'abc' 'def' 'gih'};
disp(myarray{2});

Or if you would like to keep string array:
myarray=['abc'; 'def'; 'gih'];
disp(myarray(2,:));

Branko


Branko

Subject: array of strings

From: Pekka Kumpulainen

Date: 24 Nov, 2009 13:19:20

Message: 3 of 3

"abdelmoumen " <bmoumen27@yahoo.fr> wrote in message <hegjtq$9i5$1@fred.mathworks.com>...
> hi everybody
>
> i want create an array of str like this:
> array= ['str1' 'str2' ... 'strn']
> but when i call array(1) i dont have the entire first
> str but only the first character of the first str
> for example:
> >>myarray=['abc' 'def' 'gih'];
> >>myarray(2)
> b %not 'def'
> how i do that

Use cell array:
myarray={'abc' 'def' 'gih'};
myarray{2}

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

Contact us at files@mathworks.com