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:
string vs integer representation

Subject: string vs integer representation

From: Jong-Hoon Kim

Date: 8 May, 2009 15:46:21

Message: 1 of 2

Dear programming teachers:

I guess this may be a silly question.
In MATLAB, there is a function like "num2str", "str2num", etc.
Why do we need those functions? I mean, I know how to use those
functions for my practical purposes.
But, I wonder how the computer interpret strings and integers
differently and why we need to convert them.

Thank you.

Subject: string vs integer representation

From: Matthew Whitaker

Date: 8 May, 2009 18:13:03

Message: 2 of 2

Jong-Hoon Kim <kimfinale@gmail.com> wrote in message <76edb40f-5651-49bd-9d8e-755d556d1610@s28g2000vbp.googlegroups.com>...
> Dear programming teachers:
>
> I guess this may be a silly question.
> In MATLAB, there is a function like "num2str", "str2num", etc.
> Why do we need those functions? I mean, I know how to use those
> functions for my practical purposes.
> But, I wonder how the computer interpret strings and integers
> differently and why we need to convert them.
>
> Thank you.

Basically because the underlying values for characters is not the same as their displayed representation.

for example
>> double('5')

ans =

    53

so for example:
> '5' * '6'

ans =

        2862

That's why we need the conversion functions:
>> str2num('5') * str2num('6')

ans =

    30

Tags for this Thread

No tags are associated with 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