scientific notation

15 ビュー (過去 30 日間)
Anna
Anna 2011 年 8 月 1 日
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 日
use %g instead of %i. See doc sprintf for more info.

その他の回答 (2 件)

the cyclist
the cyclist 2011 年 8 月 1 日
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 日
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.

カテゴリ

Help Center および File ExchangeFunctions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by