我是靠谱客的博主 秀丽手链,最近开发中收集的这篇文章主要介绍MATLAB数据类型,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

MATLAB 并不需要任何类型的声明或维度报表。 MATLAB 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。

如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。

例如,

Total = 42

上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。

MATLAB中可用的数据类型

MATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。

下表显示了在 MATLAB 中最常用的数据类型:

数据类型描述
int88-bit signed integer
uint88-bit unsigned integer
int1616-bit signed integer
uint1616-bit unsigned integer
int3232-bit signed integer
uint3232-bit unsigned integer
int6464-bit signed integer
uint6464-bit unsigned integer
singlesingle precision numerical data
doubledouble precision numerical data
logicallogical values of 1 or 0, represent true and false respectively
charcharacter data (strings are stored as vector of characters)
cell arrayarray of indexed cells, each capable of storing an array of a different dimension and data type
structureC-like structures, each structure having named fields capable of storing an array of a different dimension and data type
function handleyiibaier to a function
user classesobjects constructed from a user-defined class
java classesobjects constructed from a Java class

例子

创建一个脚本文件,用下面的代码:

str = 'Hello World!'
n = 2345
d = double(n)
un = uint32(789.50)
rn = 5678.92347
c = int32(rn)

上面的代码编译和执行时,它会产生以下结果:

str =
Hello World!
n =
   2345
d =
   2345
un =
   790
rn =
   5.6789e+03
c =
   5679

数据类型转换

MATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:

函数目的/作用
charConvert to character array (string)
int2strConvert integer data to string
mat2strConvert matrix to string
num2strConvert number to string
str2doubleConvert string to double-precision value
str2numConvert string to number
native2unicodeConvert numeric bytes to Unicode characters
unicode2nativeConvert Unicode characters to numeric bytes
base2decConvert base N number string to decimal number
bin2decConvert binary number string to decimal number
dec2baseConvert decimal to base N number in string
dec2binConvert decimal to binary number in string
dec2hexConvert decimal to hexadecimal number in string
hex2decConvert hexadecimal number string to decimal number
hex2numConvert hexadecimal number string to double-precision number
num2hexConvert singles and doubles to IEEE hexadecimal strings
cell2matConvert cell array to numeric array
cell2structConvert cell array to structure array
cellstrCreate cell array of strings from character array
mat2cellConvert array to cell array with potentially different sized cells
num2cellConvert array to cell array with consistently sized cells
struct2cellConvert structure to cell array

测定的数据类型

MATLAB 提供各种函数标识数据类型的变量。

下表提供了确定一个变量的数据类型的函数:

函数目的/作用
isDetect state
isaDetermine if input is object of specified class
iscellDetermine whether input is cell array
iscellstrDetermine whether input is cell array of strings
ischarDetermine whether item is character array
isfieldDetermine whether input is structure array field
isfloatDetermine if input is floating-yiibai array
ishghandleTrue for Handle Graphics object handles
isintegerDetermine if input is integer array
isjavaDetermine if input is Java object
islogicalDetermine if input is logical array
isnumericDetermine if input is numeric array
isobjectDetermine if input is MATLAB object
isrealCheck if input is real array
isscalarDetermine whether input is scalar
isstrDetermine whether input is character array
isstructDetermine whether input is structure array
isvectorDetermine whether input is vector
classDetermine class of object
validateattributesCheck validity of array
whosList variables in workspace, with sizes and types

例子

创建一个脚本文件,用下面的代码:

x = 3
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)
isnumeric(x)
 
x = 23.54
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)
isnumeric(x)
 
x = [1 2 3]
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)
 
x = 'Hello'
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)
isnumeric(x)
当运行该文件,它会产生以下结果:

x =
     3
ans =
     0
ans =
     1
ans =
     1
ans =
     1
ans =
     1
x =
   23.5400
ans =
     0
ans =
     1
ans =
     1
ans =
     1
ans =
     1
x =
     1     2     3
ans =
     0
ans =
     1
ans =
     1
ans =
     0
x =
Hello
ans =
     0
ans =
     0
ans =
     1
ans =
     0
ans =
     0


最后

以上就是秀丽手链为你收集整理的MATLAB数据类型的全部内容,希望文章能够帮你解决MATLAB数据类型所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部