scientific notation

i dont know why but matlab is printing out my y values in scientific notation which i do not want, how do i do that?
disp('table of degrees to radians')
disp(' degrees radians')
for i=0:1:36
x=5*i;
y=x*pi/180;
fprintf('\n %i %i',x,y);
end

 Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 1 Aug. 2011

0 Stimmen

use %g instead of %i. See doc sprintf for more info.

Weitere Antworten (2)

the cyclist
the cyclist am 1 Aug. 2011

0 Stimmen

disp('table of degrees to radians')
disp(' degrees radians')
for i=0:1:36
x=5*i;
y=x*pi/180;
fprintf('\n %i %f',x,y); % Changed to %f
end

1 Kommentar

Jan
Jan am 1 Aug. 2011
I think, Anna wants to display y as integer, not the other way around.

Melden Sie sich an, um zu kommentieren.

Jan
Jan am 1 Aug. 2011

0 Stimmen

The %i format displays integer values as integers, but for fractional parts the scientific notation is used. If I understand you correctly, you want to display integer values for a non-integer DOUBLE:
for i=0:1:36
x = 5*i;
y = x*pi/180;
fprintf('\n %i %.0f', x, y);
% or: fprintf('\n %i %i', x, round(y));
end
See also: FLOOR, FIX.

Kategorien

Mehr zu Functions finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by