Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Extracting string data from variable

Subject: Extracting string data from variable

From: Zemax Mat

Date: 21 Apr, 2010 14:03:05

Message: 1 of 4

I have a variable which contains strings separated by comma :

H = 'Hello,we,are,united';

I want to extract each word which is comma separated in the above variable and store them in a separate variable e.g.

a1 = 'Hello';
a2 ='we';
.
.
a4 = 'united'

I have tried sscanf but without any success. Is there any simple way of extracting words from above variable?

Thanks.

Subject: Extracting string data from variable

From: Sean

Date: 21 Apr, 2010 14:28:08

Message: 2 of 4

"Zemax Mat" <zemax2000@yahoo.com> wrote in message <hqn0ip$kbp$1@fred.mathworks.com>...
> I have a variable which contains strings separated by comma :
>
> H = 'Hello,we,are,united';
>
> I want to extract each word which is comma separated in the above variable and store them in a separate variable e.g.
>
> a1 = 'Hello';
> a2 ='we';
> .
> .
> a4 = 'united'
>
> I have tried sscanf but without any success. Is there any simple way of extracting words from above variable?
>
> Thanks.

a = regexp('hello,world,woohoo!',',','split');

Subject: Extracting string data from variable

From: Zemax Mat

Date: 21 Apr, 2010 14:53:04

Message: 3 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hqn21o$jdh$1@fred.mathworks.com>...
> "Zemax Mat" <zemax2000@yahoo.com> wrote in message <hqn0ip$kbp$1@fred.mathworks.com>...
> > I have a variable which contains strings separated by comma :
> >
> > H = 'Hello,we,are,united';
> >
> > I want to extract each word which is comma separated in the above variable and store them in a separate variable e.g.
> >
> > a1 = 'Hello';
> > a2 ='we';
> > .
> > .
> > a4 = 'united'
> >
> > I have tried sscanf but without any success. Is there any simple way of extracting words from above variable?
> >
> > Thanks.
>
> a = regexp('hello,world,woohoo!',',','split');

Thanks for your suggestion but problem is that I only know that the data is comma separated I dont know what words are stored in the string. Instead of 'hello' it could have 'Data'.

Subject: Extracting string data from variable

From: Zemax Mat

Date: 21 Apr, 2010 14:56:04

Message: 4 of 4

"Zemax Mat" <zemax2000@yahoo.com> wrote in message <hqn3gg$haa$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hqn21o$jdh$1@fred.mathworks.com>...
> > "Zemax Mat" <zemax2000@yahoo.com> wrote in message <hqn0ip$kbp$1@fred.mathworks.com>...
> > > I have a variable which contains strings separated by comma :
> > >
> > > H = 'Hello,we,are,united';
> > >
> > > I want to extract each word which is comma separated in the above variable and store them in a separate variable e.g.
> > >
> > > a1 = 'Hello';
> > > a2 ='we';
> > > .
> > > .
> > > a4 = 'united'
> > >
> > > I have tried sscanf but without any success. Is there any simple way of extracting words from above variable?
> > >
> > > Thanks.
> >
> > a = regexp('hello,world,woohoo!',',','split');
>
> Thanks for your suggestion but problem is that I only know that the data is comma separated I dont know what words are stored in the string. Instead of 'hello' it could have 'Data'.

Thanks Seans. I used the code that you suggested and it worked perfectly fine.

Tags for this Thread

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.

Contact us