QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3421|回复: 1
打印 上一主题 下一主题

MATLAB数据类型

[复制链接]
字体大小: 正常 放大

326

主题

32

听众

1万

积分

  • TA的每日心情
    慵懒
    2020-7-12 09:52
  • 签到天数: 116 天

    [LV.6]常住居民II

    管理员

    群组2018教师培训(呼和浩

    群组2017-05-04 量化投资实

    群组2017“草原杯”夏令营

    群组2018美赛冲刺培训

    群组2017 田老师国赛冲刺课

    跳转到指定楼层
    1#
    发表于 2020-1-20 16:59 |只看该作者 |正序浏览
    |招呼Ta 关注Ta
    MATLAB 并不需要任何类型的声明或维度报表。 MATLAB 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。2 F: ~& X9 `8 a7 r) n! A) v& \

    ' x5 ]; P" S7 Q7 l6 z如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。
    6 ?8 ~* e+ `3 A. T0 V
    3 c3 b( }- d5 W$ h; x0 L例如,
    * {. `& g+ }) g$ V; n0 r8 d, I0 u- g: R
    Total = 42: B- f  H. \! J, X9 M5 s
    上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。3 U2 [  {3 \( o5 p5 M. A

    # i. \8 s- l) ^3 v+ d; b( TMATLAB中可用的数据类型+ |5 u! D5 A" M
      T$ o+ }$ E; i" y
    MATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。
    ( l, c) v, G/ m6 R3 r# `. i4 b- t4 Y+ E) B2 L7 o! C- H: ~
    下表显示了在 MATLAB 中最常用的数据类型:: v0 S, N$ O. Y* E. H0 I0 s
    " e: M' W9 r+ s9 Y, H' D6 ~
    数据类型        描述
    ' N% W, _. \6 d( eint8        8-bit signed integer* ~$ x4 q& h' x, Y4 X9 O
    uint8        8-bit unsigned integer) p" u+ P4 V* b+ K4 S) f/ o% d$ F* A
    int16        16-bit signed integer/ b( W0 \4 @, A$ y0 I  f9 |
    uint16        16-bit unsigned integer
    : o; n! R& h5 z/ ^0 T  t: Oint32        32-bit signed integer3 a" @  x/ F8 c& G$ b- O
    uint32        32-bit unsigned integer, u7 [2 i- s1 C* n$ K
    int64        64-bit signed integer8 k! M' J/ H9 M( p
    uint64        64-bit unsigned integer4 G1 n/ n6 d1 i4 }! Q
    single        single precision numerical data
    : l; `/ ?2 |, ~! H' adouble        double precision numerical data8 K' C% g  S* R# O
    logical        logical values of 1 or 0, represent true and false respectively
    0 S- u5 I. P$ Fchar        character data (strings are stored as vector of characters)
    & d/ P# G, u# @- u  }9 ycell array        array of indexed cells, each capable of storing an array of a different dimension and data type
    / e" _4 s+ t& N2 Q- X/ i- bstructure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type! E! h7 V2 m, E3 B
    function handle        yiibaier to a function5 n% z% X& l* y4 d% R9 g  e, B
    user classes        objects constructed from a user-defined class6 |, d: H8 U& ?+ M2 W7 O" V
    java classes        objects constructed from a Java class+ m- D* u. T. a( k* E! U
    例子
    + A: x! q% E. _7 e! a$ o
    : K0 r: }# S0 m. [/ ?创建一个脚本文件,用下面的代码:
    , }. U( B$ w* N4 r) z7 V( w, k# f3 f* r9 i: M7 |/ W
    str = 'Hello World!'( g( h/ C$ t/ }1 A/ g
    n = 2345! t9 Q' I- C& h% H$ i+ P& d# q# R
    d = double(n)
    , \- E; A+ v  g9 v' }% }un = uint32(789.50)
    ! ]4 `, B& G: Jrn = 5678.92347
    - p- j$ F! _) c9 d% Q" jc = int32(rn): J. d. D% \+ X, b! i6 n
    上面的代码编译和执行时,它会产生以下结果:- S2 K! c5 V1 R" l  q( \

    " J3 ^0 g# w9 f/ l& G% q+ r! N' Jstr =
    % i$ L! a2 z2 A  v# sHello World!1 P1 n3 D7 M/ _6 S: i4 `
    n =
    9 z; `- G$ J9 K' n   2345
    9 @- A, [4 Z6 O, Y; x) e0 Hd =
    ) T+ W3 n" Y8 R! y7 p( _   2345
    3 c$ p& L0 S( Nun =
      u# O; }, a; ~6 H- u) i   790, Y) m# ^. M% ~) P
    rn =
    % }+ r0 |' o+ Z   5.6789e+03  o8 `8 e+ e" s9 B7 N& W# h( ~
    c =% H! p+ o" o1 p) h( e0 g6 f
       5679; o$ o' d8 h9 o3 m  G& n3 H
    数据类型转换+ O+ a8 i6 t! E2 ]

    7 P, A  J0 g2 D! ^- FMATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:
    & U3 K+ j  E' t; P- R, c% H# m$ h1 X5 R3 \% _$ B0 @- a+ @
    函数        目的/作用
    3 ]1 {9 Z3 T  W: Nchar        Convert to character array (string)# l' }9 `* _' [$ v! F! q& k; u2 B# ?) u
    int2str        Convert integer data to string4 Z7 z3 b1 C$ R
    mat2str        Convert matrix to string2 f$ R& Z2 S" ^8 D
    num2str        Convert number to string" Z5 ^( g( g/ T$ r. U) g+ T
    str2double        Convert string to double-precision value- S* F% w4 v5 i- z, G
    str2num        Convert string to number) R/ o7 t- `( c# b8 i. I6 W
    native2unicode        Convert numeric bytes to Unicode characters
    5 ]) q; s* y2 hunicode2native        Convert Unicode characters to numeric bytes
    # b" p9 ~- P9 X7 F9 M9 L5 j2 nbase2dec        Convert base N number string to decimal number/ h. w# O- z4 c$ E0 n7 j
    bin2dec        Convert binary number string to decimal number  G) @( q$ c- A1 Q% `
    dec2base        Convert decimal to base N number in string6 W' }7 t) c7 b: ]
    dec2bin        Convert decimal to binary number in string' q  `6 T# ?9 G1 C* ~7 u- O( J
    dec2hex        Convert decimal to hexadecimal number in string
    / Z3 S' ]) o4 `7 uhex2dec        Convert hexadecimal number string to decimal number4 i- Z9 D5 P; ^/ b/ J$ m9 q, D
    hex2num        Convert hexadecimal number string to double-precision number  m" R5 e* J$ a
    num2hex        Convert singles and doubles to IEEE hexadecimal strings/ ?( F# P  g' R) m+ y
    cell2mat        Convert cell array to numeric array
    " E7 `0 Y( Y* Tcell2struct        Convert cell array to structure array
    3 R( l% u" X0 @% _6 ?cellstr        Create cell array of strings from character array
    ( R- Y8 B6 n8 {, |mat2cell        Convert array to cell array with potentially different sized cells
    ) s$ n. @# o' [, ?6 E$ i+ [2 C7 Pnum2cell        Convert array to cell array with consistently sized cells, G( E3 P& x5 _- c- h1 F
    struct2cell        Convert structure to cell array$ L' t# G, t. e: k
    测定的数据类型6 r! g% i9 t' V! }9 k5 G

    3 ]+ O6 g7 Q& h# G! R' X7 U( ?MATLAB 提供各种函数标识数据类型的变量。
    4 [) S" q7 e. y. i; J' r0 S* h' L# T" T' @% n) z" t
    下表提供了确定一个变量的数据类型的函数:
    1 e0 A  v$ r* w$ h. U# k( w( z: ~# Y2 `7 k
    函数        目的/作用: n3 @0 O. I8 T# }
    is        Detect state
    & O9 a  G3 |9 f9 F7 h6 T$ Nisa        Determine if input is object of specified class
    2 v9 F, {/ u, M+ {; y$ b. j2 _iscell        Determine whether input is cell array+ a! w9 f" [' q- O5 u
    iscellstr        Determine whether input is cell array of strings% I5 \+ M$ d$ `* R7 L6 Z6 a! B- z
    ischar        Determine whether item is character array
    & P1 [" T2 B$ Z3 i. W0 u9 Nisfield        Determine whether input is structure array field
    : Z# _8 g; H; i5 A& \* N0 _isfloat        Determine if input is floating-yiibai array8 w& N  J: A7 m' |; l. n
    ishghandle        True for Handle Graphics object handles  S2 T5 C4 `; |" C
    isinteger        Determine if input is integer array
    9 J5 x" G& O$ e1 o' Jisjava        Determine if input is Java object
    : B6 {" k9 V9 }" Rislogical        Determine if input is logical array
    & \% h" B/ h1 }6 t* cisnumeric        Determine if input is numeric array$ [4 Y; U4 ^+ S9 G0 w% V
    isobject        Determine if input is MATLAB object
    . A. `' b6 c( F1 Gisreal        Check if input is real array1 r+ ~/ C- u# W2 M
    isscalar        Determine whether input is scalar
    8 L( f" i- R  a3 z* Sisstr        Determine whether input is character array( F7 D: D% A  ?; h2 A
    isstruct        Determine whether input is structure array
    , N$ U/ ?# C2 c7 bisvector        Determine whether input is vector
    7 }/ ?- S. R' d  e2 W5 |class        Determine class of object
    7 o" i$ c  |, I1 f3 t5 mvalidateattributes        Check validity of array
    : u/ W. w% k/ w2 ?% Vwhos        List variables in workspace, with sizes and types
    9 E2 r: T6 s3 G2 u4 t1 Z4 K例子
    8 q& y- z2 |# m! E+ T: }! Q: d- |  m3 }# e+ K$ W9 Z8 S# T2 B
    创建一个脚本文件,用下面的代码:
    5 i; K: v/ l5 ^( v
    8 S4 k; Q9 t; t+ h( C& U: U( ?x = 3. B; O3 j4 n( w% ?$ b. s3 N! k; ?
    isinteger(x)
    ( m9 Q8 U; Z4 L9 k/ c- x% cisfloat(x)
    : y. b" {  I& f  n( aisvector(x)
      q& }$ X7 T' @$ zisscalar(x)
    7 _! |, `* I* i( G3 S' t; q. Jisnumeric(x)
    ! r3 V2 B, X! ^8 J+ l' M; u4 ~
    x = 23.54
    : k$ C- _0 y1 J  o' q. u+ V8 o5 Y4 bisinteger(x)0 B5 v/ ~1 l& g3 T
    isfloat(x)% Y; p: k" S* P/ {! @7 e
    isvector(x)7 h1 g# z/ {2 z
    isscalar(x), V. J- T5 F+ {7 G
    isnumeric(x)
    3 C9 S. T  G4 _; l1 z% K* L6 c/ L4 [  X7 J
    x = [1 2 3]3 E. p- U% T* l! ?7 d1 T
    isinteger(x)% Y  d( m" r" I2 k! k) S
    isfloat(x)( f6 o9 ]$ A( F' F4 A: b1 I$ Q6 }
    isvector(x)
    ! s) o6 u! Q3 X, Oisscalar(x)
    5 b. [) C0 Q. ]3 l+ x# f3 z$ U! ]; l7 `
    x = 'Hello'
    0 ~9 }' `+ m' K$ disinteger(x)3 c; Q$ S) }5 s4 N$ F  j
    isfloat(x)  H5 z; @4 j; W
    isvector(x). i7 }$ ]7 F! t  w6 v0 p; b
    isscalar(x)
    9 _% S8 W+ n. T) Z+ l) @* `isnumeric(x)4 j6 T8 Z& X6 [
    当运行该文件,它会产生以下结果:/ X8 n0 F" o% m8 A
    , c) j3 O8 f( [9 }3 v7 A
    x =" t* \1 a5 g8 h  [0 j
         3
    $ a' F1 {! f( r" b, |ans =) ~& W: m$ }' L( \2 w) o9 `
         02 p2 s# M  P$ r" n* ~
    ans =1 q" [  Y& d3 g3 I/ |
         1
    0 _1 f1 m/ v5 d- |1 E1 s: n+ r4 yans =
    $ K5 j7 {. w; ~5 J4 U8 k) U0 N     1) V& U0 s! k0 s7 _4 P
    ans =
    7 P3 B1 A" f. e  C* Z     1
    , x  m4 W; f+ i" F+ S! a- |ans =
    7 c1 {% ?0 Q3 v1 a# M, ?; u5 i     1
    ) [4 W5 R3 B! e$ e/ p4 ix =2 _- S' }" Y: ?
       23.5400  G( R2 c% U+ Z5 ]* ~3 Y: o
    ans =+ z+ p7 u  h1 A5 _- s( Q2 z
         0) R2 j& c2 @& s, v
    ans =
    - ?. P  m9 D, C( i0 q: c  }     1, K4 r' I8 \9 }6 D6 a7 _* z2 p
    ans =+ u8 v4 `' v3 N1 O
         1
    5 O- X! H( }% G: t; @ans =3 d9 w/ ?4 w( E* n
         1" b1 n" C# m" i' A% k, `( O; f9 d7 z  `
    ans =- H: f. N4 k8 Z9 N* K* @- k
         1
    ' y; m+ a* E8 C4 F  c! Ix =
    4 x" y$ M' E% j" ~2 D6 O     1     2     3
    " p# y5 d8 v, u4 {. Uans =% J) I& b6 O8 h6 `8 T1 P- `
         0
    ( `' J; r! k* p+ y" Hans =  ]1 O0 B- j: \/ ~( @" y0 H7 C& y0 C, P
         1# h; f* O/ g" F4 Q# {
    ans =8 l' [9 b9 ?2 O4 R* `
         1
    6 V4 y( y& Z, t. dans =. |8 t  N; W/ _. ], ^5 H4 `, s
         0- O+ ~+ J3 f0 g7 v% W" L! _( Z7 t
    x =5 r' t2 n. g) g
    Hello; @2 Z3 v7 M% W& j9 C- {3 v6 G8 R3 T
    ans =# A7 u1 H* ]3 j- N- w
         0
    2 f: y0 b/ l. ]& ?8 w2 |/ aans =5 Q  K. F' z2 M) ~7 t
         0
    & @9 W) _( |) U# W8 H4 Rans =
    $ e: w9 u. t: L* g8 r) Z- h( {" P, y, i, `% u     18 G& F" c: F8 l5 R. a  J
    ans =
    ! x5 z0 o+ b1 P( D8 `% t! @2 k9 Y     0
    , a' v' V* A0 ^+ i1 Q6 ]) uans =+ Q# }1 F9 N% e! c4 H
         0
    2 y1 R. a1 c6 Z+ }
    4 {$ w) W, K8 t' h: Z————————————————
    " G$ K1 V+ [2 F, |: t2 Y版权声明:本文为CSDN博主「Phil__ming」的原创文章。
    4 ~5 s7 N: w  G* G: \% i原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575
    % z- n) ]1 W2 y$ h
    6 o: d( E' F" p$ j( D. D4 }1 T( R8 \( X
    zan
    转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信

    0

    主题

    1

    听众

    59

    积分

    升级  56.84%

  • TA的每日心情
    开心
    2020-3-22 18:15
  • 签到天数: 14 天

    [LV.3]偶尔看看II

    邮箱绑定达人

    群组数学建模美赛备战群组

    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册地址

    qq
    收缩
    • 电话咨询

    • 04714969085
    fastpost

    关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

    手机版|Archiver| |繁體中文 手机客户端  

    蒙公网安备 15010502000194号

    Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

    GMT+8, 2026-8-8 01:55 , Processed in 2.074584 second(s), 58 queries .

    回顶部