Thread Subject: String Array Problems

Subject: String Array Problems

From: Gav Dooley

Date: 24 Nov, 2009 11:55:07

Message: 1 of 3

Hi, I was wondering if anybody can help me,

I want to do a few things using 2d arrays but am having difficulty.
1) can i add two arrays of equal size which will result in a being read first, then bfor example,

if a = [ 'w' ; 'x'] ;
b = ['t' ; 'y' ] ;
c = a+b ; (Or smoething along those lines....

how can i get:
c=

w
x
t
y

I seem to just be getting back numbers....

2) can i set a variable string of x = ' hello' ;
and place it within an array like this somehow:

a = [ 'l' ; x (hello) ; 'f' ] etc...

Thanks, Im pretty new to matlab so these may be stupid questions, thanks!

Subject: String Array Problems

From: Branko

Date: 24 Nov, 2009 12:22:03

Message: 2 of 3

"Gav Dooley" <dooleygav@yahoo.co.uk> wrote in message <heghir$ari$1@fred.mathworks.com>...
> Hi, I was wondering if anybody can help me,
>
> I want to do a few things using 2d arrays but am having difficulty.
> 1) can i add two arrays of equal size which will result in a being read first, then bfor example,
>
> if a = [ 'w' ; 'x'] ;
> b = ['t' ; 'y' ] ;
> c = a+b ; (Or smoething along those lines....
>
> how can i get:
> c=
>
> w
> x
> t
> y
>
> I seem to just be getting back numbers....


>
> 2) can i set a variable string of x = ' hello' ;
> and place it within an array like this somehow:
>
> a = [ 'l' ; x (hello) ; 'f' ] etc...
>
> Thanks, Im pretty new to matlab so these may be stupid questions, thanks!

1)
> how can i get:
> c=
>
> w
> x
> t
> y

a = [ 'w' ; 'x'] ;
b = ['t' ; 'y' ] ;
c=[a(:);b(:)]

2) If you would like to do as you described, you'll get error.Because x(hello) is string and has to be in quote. Other thing is that you have to use cell array
a = { 'l' ; 'x (hello)' ; 'f'}

Branko

Subject: String Array Problems

From: ImageAnalyst

Date: 24 Nov, 2009 12:24:42

Message: 3 of 3

On Nov 24, 6:55 am, "Gav Dooley" <dooley...@yahoo.co.uk> wrote:
> Hi, I was wondering if anybody can help me,
>
> I want to do a few things using 2d arrays but am having difficulty.
> 1) can i add two arrays of equal size which will result in a being read first, then bfor example,
>
> if a = [ 'w' ; 'x'] ;
> b = ['t' ; 'y' ] ;
> c = a+b ; (Or smoething along those lines....
>
> how can i get:
> c=
>
> w
> x
> t
> y
>
> I seem to just be getting back numbers....
>
> 2) can i set a variable string of x = ' hello' ;
> and place it within an array like this somehow:
>
> a = [ 'l' ; x (hello) ; 'f' ] etc...
>
> Thanks, Im pretty new to matlab so these may be stupid questions, thanks!

-------------------------------------------------------
1. c = [a;b]
It prints out letters for me, not numbers.

2. I think for different length strings you need to use a cell array,
like this:
x = 'hello';
a = {'l' ; x ; 'f'}

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
cell array Branko 24 Nov, 2009 07:24:06
array Gav Dooley 24 Nov, 2009 06:59:05
string Gav Dooley 24 Nov, 2009 06:59:04
rssFeed for this Thread

Contact us at files@mathworks.com