在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 數(shù)據(jù)分析&挖掘/ Matlab數(shù)字
Matlab代數(shù)(方程求解)
Matlab開(kāi)發(fā)環(huán)境設(shè)置
Matlab GNU Octave
Matlab字符串
Matlab矩陣
Matlab微分和導(dǎo)數(shù)
Matlab數(shù)字
Matlab數(shù)據(jù)導(dǎo)入
Matlab整合集成
Matlab冒號(hào)符號(hào)
Matlab變量
Matlab數(shù)組
Matlab運(yùn)算符
Matlab數(shù)據(jù)導(dǎo)出
Matlab向量
Matlab命令
Matlab決策
Matlab微積分
Matlab圖形
Matlab教程
Matlab繪圖
Matlab多項(xiàng)式
Matlab .m腳本文件
Matlab循環(huán)
Matlab基礎(chǔ)語(yǔ)法
Matlab函數(shù)
Matlab轉(zhuǎn)換
Matlab概述
Matlab數(shù)據(jù)類型

Matlab數(shù)字

MATLAB支持包括有符號(hào)和無(wú)符號(hào)整數(shù)以及單精度和雙精度浮點(diǎn)數(shù)的各種數(shù)字類型。 默認(rèn)情況下,MATLAB將所有數(shù)值存儲(chǔ)為雙精度浮點(diǎn)數(shù)。

可以選擇將任何數(shù)字或數(shù)組的數(shù)字存儲(chǔ)為整數(shù)或單精度數(shù)字。

所有數(shù)字類型都支持基本的數(shù)組運(yùn)算和數(shù)學(xué)運(yùn)算。

轉(zhuǎn)換為各種數(shù)值數(shù)據(jù)類型

MATLAB提供以下函數(shù)來(lái)將數(shù)值轉(zhuǎn)換為各種數(shù)字?jǐn)?shù)據(jù)類型 -

函數(shù) 描述說(shuō)明
double 轉(zhuǎn)換為雙精度數(shù)
single 轉(zhuǎn)換為單精度數(shù)
int8 轉(zhuǎn)換為8位有符號(hào)整數(shù)
int16 轉(zhuǎn)換為16位有符號(hào)整數(shù)
int32 轉(zhuǎn)換為32位有符號(hào)整數(shù)
int64 轉(zhuǎn)換為64位有符號(hào)整數(shù)
uint8 轉(zhuǎn)換為8位無(wú)符號(hào)整數(shù)
uint16 轉(zhuǎn)換為16位無(wú)符號(hào)整數(shù)
uint32 轉(zhuǎn)換為32位無(wú)符號(hào)整數(shù)
uint64 轉(zhuǎn)換為64位無(wú)符號(hào)整數(shù)

示例

創(chuàng)建腳本文件并鍵入以下代碼 -

x = single([5.32 3.47 6.28]) .* 7.5
x = double([5.32 3.47 6.28]) .* 7.5
x = int8([5.32 3.47 6.28]) .* 7.5
x = int16([5.32 3.47 6.28]) .* 7.5
x = int32([5.32 3.47 6.28]) .* 7.5
x = int64([5.32 3.47 6.28]) .* 7.5

執(zhí)行上面示例代碼,得到以下結(jié)果 -

x =

   39.900   26.025   47.100

x =

   39.900   26.025   47.100

x =

  38  23  45

x =

  38  23  45

x =

  38  23  45

x =

  38  23  45

示例

讓我們?cè)賮?lái)擴(kuò)展上面的例子。 創(chuàng)建腳本文件并鍵入以下代碼 -

x = int32([5.32 3.47 6.28]) .* 7.5
x = int64([5.32 3.47 6.28]) .* 7.5
x = num2cell(x)

執(zhí)行上面示例代碼,得到以下結(jié)果 -

Trial>> x = int32([5.32 3.47 6.28]) .* 7.5
x = int64([5.32 3.47 6.28]) .* 7.5
x = num2cell(x)

x =

  1×3 int32 行向量

   38   23   45


x =

  1×3 int64 行向量

   38   23   45


x =

  1×3 cell 數(shù)組

    {[38]}    {[23]}    {[45]}

最小和最大的整數(shù)

intmax()intmin()函數(shù)返回可以用所有類型的整數(shù)表示的最大值和最小值。

這兩個(gè)函數(shù)將整數(shù)數(shù)據(jù)類型作為參數(shù),例如int_max(int8)intmin(int64),并返回可以使用整數(shù)數(shù)據(jù)類型表示的最大值和最小值。

示例

以下示例說(shuō)明如何獲取最小和最大的整數(shù)值。 創(chuàng)建腳本文件并在其中寫下面的代碼 -

% displaying the smallest and largest signed integer data
str = 'The range for int8 is:\n\t%d to %d ';
sprintf(str, intmin('int8'), intmax('int8'))
str = 'The range for int16 is:\n\t%d to %d ';
sprintf(str, intmin('int16'), intmax('int16'))
str = 'The range for int32 is:\n\t%d to %d ';
sprintf(str, intmin('int32'), intmax('int32'))
str = 'The range for int64 is:\n\t%d to %d ';
sprintf(str, intmin('int64'), intmax('int64'))

% displaying the smallest and largest unsigned integer data
str = 'The range for uint8 is:\n\t%d to %d ';
sprintf(str, intmin('uint8'), intmax('uint8'))
str = 'The range for uint16 is:\n\t%d to %d ';
sprintf(str, intmin('uint16'), intmax('uint16'))
str = 'The range for uint32 is:\n\t%d to %d ';
sprintf(str, intmin('uint32'), intmax('uint32'))
str = 'The range for uint64 is:\n\t%d to %d ';
sprintf(str, intmin('uint64'), intmax('uint64'))

執(zhí)行上面示例代碼,得到以下結(jié)果 -

ans =

    'The range for int8 is:
         -128 to 127 '


ans =

    'The range for int16 is:
         -32768 to 32767 '


ans =

    'The range for int32 is:
         -2147483648 to 2147483647 '


ans =

    'The range for int64 is:
         -9223372036854775808 to 9223372036854775807 '


ans =

    'The range for uint8 is:
         0 to 255 '


ans =

    'The range for uint16 is:
         0 to 65535 '


ans =

    'The range for uint32 is:
         0 to 4294967295 '


ans =

    'The range for uint64 is:
         0 to 1.844674e+19 '

最小和最大的浮點(diǎn)數(shù)

realmax()realmin()函數(shù)返回可以用浮點(diǎn)數(shù)表示的最大值和最小值。

當(dāng)使用參數(shù)'single'調(diào)用這兩個(gè)函數(shù)時(shí),返回使用單精度數(shù)據(jù)類型表示的最大值和最小值,當(dāng)使用參數(shù)'double'調(diào)用時(shí),返回可以表示的最大值和最小值的雙精度數(shù)據(jù)類型。

示例

以下示例說(shuō)明如何獲取最小和最大的浮點(diǎn)數(shù)。 創(chuàng)建腳本文件并在其中寫下面的代碼 -

% displaying the smallest and largest single-precision 
% floating point number
str = 'The range for single is:\n\t%g to %g and\n\t %g to  %g';
sprintf(str, -realmax('single'), -realmin('single'), ...
   realmin('single'), realmax('single'))
% displaying the smallest and largest double-precision 
% floating point number
str = 'The range for double is:\n\t%g to %g and\n\t %g to  %g';
sprintf(str, -realmax('double'), -realmin('double'), ...
   realmin('double'), realmax('double'))

執(zhí)行上面示例代碼,得到以下結(jié)果 -

ans =

    'The range for single is:
         -3.40282e+38 to -1.17549e-38 and
          1.17549e-38 to  3.40282e+38'


ans =

    'The range for double is:
         -1.79769e+308 to -2.22507e-308 and
          2.22507e-308 to  1.79769e+308'

上一篇:Matlab .m腳本文件下一篇:Matlab字符串