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:
adding scalar to a vector in matlab

Subject: adding scalar to a vector in matlab

From: Srikrishna Mahadevan

Date: 3 Feb, 2012 02:42:17

Message: 1 of 2

Hi,

I am trying to offset my vector by a real number; but for some reason matlab makes it a decimal number when the offset is ~1000; Does anyone know why is this happening and how I can overcome it?

Actually the added number is being converted to a decimal number.

Please respond asap.

Thanks.
Sri

Subject: adding scalar to a vector in matlab

From: Roger Stafford

Date: 3 Feb, 2012 04:03:11

Message: 2 of 2

"Srikrishna Mahadevan" <krishna086@gmail.com> wrote in message <jgfhi9$2dd$1@newscl01ah.mathworks.com>...
> I am trying to offset my vector by a real number; but for some reason matlab makes it a decimal number when the offset is ~1000; Does anyone know why is this happening and how I can overcome it?
> Actually the added number is being converted to a decimal number.
- - - - - - - - - -
  It is not entirely clear what you mean by "converted to a decimal number". However I am guessing you refer to the display of numbers using the default "format short" which Mathworks describes as "Scaled fixed-point format, with 4 digits after the decimalpoint. For example, 3.1416." There are many other kinds of format used to display your numbers. Look up the documentation on the 'format' instruction.

  However it is important for you to realize that these are simply different methods the matlab system uses to inform you about an internally-stored quantity. With different formats the same number pi can appear as:

 3.2416 (short)
 3.14159265358979 (long)
 400921fb54442d18 (ieee hex)

Using for example "%16.10e" in fprintf you would see:

 3.1415926536e+00

  All of these are attempts at showing you, the user, what quantity is contained within the computer, but that internal number is the same no matter how it is being displayed - computation results are unaffected by differences in display. There is no "converting" taking place here. In the standard type 'double' numbers the representation internally is actually in binary floating point using 64 bits. The relationship to decimal numbers is only theoretical, achieved by way of format displays. The above mysterious "ieee hex" format is the only one that corresponds exactly to the actual state of those 64 'double' bits.

  I would suggest you do some experimentation using many different formats on the same number to demonstrate all of this to your own satisfaction.

Roger Stafford

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