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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

how to display answer in a particular format

Asked by Elysi Cochin on 22 Mar 2013

i got an answer as

-7.28135827387422e-05

1.87033878860991e-35

3.860575156847749e+003

i wanted to get the answers as

72.813

18.703

38.605

i want only this format and the value should be positive

how to do the conversion after getting the value..... please do reply...

0 Comments

Elysi Cochin

Tags

Products

No products are associated with this question.

1 Answer

Answer by Image Analyst on 22 Mar 2013
Accepted answer

Try this:

a = -7.28135827387422e-05
aString = num2str(a)
decimalLocation = strfind(aString, '.')
aString = [aString(1:decimalLocation-1), aString(decimalLocation+1), '.', aString(decimalLocation+1:decimalLocation+3)]
aNumber = str2double(aString)
b = 1.87033878860991e-35
bString = num2str(b)
decimalLocation = strfind(bString, '.')
bString = [bString(1:decimalLocation-1), bString(decimalLocation+1), '.', bString(decimalLocation+1:decimalLocation+3)]
bNumber = str2double(bString)

1 Comment

Elysi Cochin on 22 Mar 2013

thank u sir...

Image Analyst

Contact us