Got Questions? Get Answers.
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:
What %i s this?

Subject: What %i s this?

From: Pasco Alquim

Date: 3 Nov, 2011 22:24:28

Message: 1 of 4

>> sprintf('%i', 38.3)

ans =

3.830000e+001

????

Subject: What %i s this?

From: dpb

Date: 3 Nov, 2011 22:32:51

Message: 2 of 4

On 11/3/2011 5:24 PM, Pasco Alquim wrote:
>>> sprintf('%i', 38.3)
>
> ans =
>
> 3.830000e+001
>
> ????

An ignored one... :)

It's not valid field and it seem Matlab doesn't care so defaults to the
effect of the underlying data type a double.

--

Subject: What %i s this?

From: Pasco Alquim

Date: 3 Nov, 2011 23:02:14

Message: 3 of 4

dpb <none@non.net> wrote in message <j8v4qf$f6k$1@speranza.aioe.org>...
> On 11/3/2011 5:24 PM, Pasco Alquim wrote:
> >>> sprintf('%i', 38.3)
> >
> > ans =
> >
> > 3.830000e+001
> >
> > ????
>
> An ignored one... :)
>
> It's not valid field and it seem Matlab doesn't care so defaults to the
> effect of the underlying data type a double.

No, not ignored. See first row in table at

http://www.mathworks.com/help/techdoc/ref/fprintf.html

Subject: What %i s this?

From: dpb

Date: 4 Nov, 2011 01:47:38

Message: 4 of 4

On 11/3/2011 6:02 PM, Pasco Alquim wrote:
...

> No, not ignored. See first row in table at
>
> http://www.mathworks.com/help/techdoc/ref/fprintf.html

Hmmm....that postdates my version of Matlab-- 'i' isn't listed here as a
synonym for 'd'. Wonder why they did that???

Anyway, it still is so that Matlab accepts a numeric field descriptor
but reverts to the effect of %f for underlying data type of double.
Whether that behavior mimics C or not I'm not adept enough to know otomh.

If you expected

sprintf('%i',38.3)

to yield 38, that doesn't occur; you'll need fix() for that. I'd
_presume_ it wouldn't happen in C, either, but that is a presumption.

--

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