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

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 8월 1일

0 개 추천

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

추가 답변 (2개)

the cyclist
the cyclist 2011년 8월 1일

0 개 추천

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

Jan
Jan 2011년 8월 1일
I think, Anna wants to display y as integer, not the other way around.

댓글을 달려면 로그인하십시오.

Jan
Jan 2011년 8월 1일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Functions에 대해 자세히 알아보기

질문:

2011년 8월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by