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:
Small problem with strcat

Subject: Small problem with strcat

From: Robin Jens

Date: 2 Jan, 2011 11:01:05

Message: 1 of 3

Hello everybody

I have the following example:

cellaray1={'Heineken' 'Carlsberg'}

Price={10 30}

strcat(cellaray1,{'-'},Price)

I get:

>> strcat(cellaray1,{'-'},Price)

ans =

    [1x10 char] 'Carlsberg-'

I want:

Heineken-10
Carlsberg-30

The problem is the numeric data in Price.

Best Regards

Robin Jens

Subject: Small problem with strcat

From: Oleg Komarov

Date: 2 Jan, 2011 13:43:05

Message: 2 of 3

"Robin Jens" wrote in message <ifplth$i0$1@fred.mathworks.com>...
> Hello everybody
>
> I have the following example:
>
> cellaray1={'Heineken' 'Carlsberg'}
>
> Price={10 30}
>
> strcat(cellaray1,{'-'},Price)
>
> I get:
>
> >> strcat(cellaray1,{'-'},Price)
>
> ans =
>
> [1x10 char] 'Carlsberg-'
>
> I want:
>
> Heineken-10
> Carlsberg-30
>
> The problem is the numeric data in Price.
>
> Best Regards
>
> Robin Jens

You have the convert 30 to '30'.
Try char([10,30]) and see what happens (hint: google for an ascii table).

To convert a number to its correspondent string form use sprintf('%d',10) or num2str(10).
I also suggest to store the prices in a double array rather than in a cell.

Oleg

Subject: Small problem with strcat

From: Robin Jens

Date: 8 Jan, 2011 09:41:04

Message: 3 of 3

"Oleg Komarov" <oleg.komarovRemove.this@hotmail.it> wrote in message <ifpvd9$6gs$1@fred.mathworks.com>...
> "Robin Jens" wrote in message <ifplth$i0$1@fred.mathworks.com>...
> > Hello everybody
> >
> > I have the following example:
> >
> > cellaray1={'Heineken' 'Carlsberg'}
> >
> > Price={10 30}
> >
> > strcat(cellaray1,{'-'},Price)
> >
> > I get:
> >
> > >> strcat(cellaray1,{'-'},Price)
> >
> > ans =
> >
> > [1x10 char] 'Carlsberg-'
> >
> > I want:
> >
> > Heineken-10
> > Carlsberg-30
> >
> > The problem is the numeric data in Price.
> >
> > Best Regards
> >
> > Robin Jens
>
> You have the convert 30 to '30'.
> Try char([10,30]) and see what happens (hint: google for an ascii table).
>
> To convert a number to its correspondent string form use sprintf('%d',10) or num2str(10).
> I also suggest to store the prices in a double array rather than in a cell.
>
> Oleg

Thank you very much Oleg

You are of great help.

Best Regards

Robin Jens

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