How to increase the precision in my output using structures

Hi guys,
I'm running a program that needs more precision in the output. I have tried to use format long, but the output using the structure still reports without decimal places. Any suggestions?
Thanks
>> a = 3e-6*(s(1).pixels(2)).^2 + 0.0097*(s(1).pixels(2)) + 2.8827
a =
8
>> s(1).pixels(2)
ans =
531
>> a = 3e-6*(531).^2 + 0.0097*(531) + 2.8827
a =
8.8793

Réponses (1)

James Tursa
James Tursa le 20 Avr 2015
Modifié(e) : James Tursa le 20 Avr 2015
I would assume s(1).pixels is some type of integer class instead of double, so you are getting an integer result. Either convert s(1).pixels to double first, or wrap the access with a double in the calculation. E.g.,
s(1).pixels = double(s(1).pixels);
or
a = 3e-6*(double(s(1).pixels(2))).^2 + 0.0097*(double(s(1).pixels(2))) + 2.8827

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by