QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3424|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。7 A4 m& t+ W7 v4 C- U. G6 ^/ K
    , N! M8 B# n8 u, M% z
    如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。
    # c6 l  _1 g9 r' v/ z5 Y% `) \6 k2 ]. _1 G
    例如,
    / k" E; B& z8 z% Z0 ~
    2 b& b3 n  h" ~& d) f+ BTotal = 421 w) F2 V5 s( |
    上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。
    / }( h+ q2 e: Y; o4 a1 Y
    . g" b' J) e+ _* uMATLAB中可用的数据类型
    2 {; Y" Z1 J; I- E3 [
    ! M2 ]/ Z1 }' m) \+ ?. u  XMATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。/ h8 Z! N( l. R  f! f$ i: F# c
    % E/ R/ F$ o9 R
    下表显示了在 MATLAB 中最常用的数据类型:7 q. y# ?: V$ C6 x4 f" [+ |1 ]

    0 W3 e% [5 O- n3 Q  n$ y数据类型        描述
    , a" y/ U8 W7 Y: a4 iint8        8-bit signed integer
    : H& |& K  }! Q8 a' X, Fuint8        8-bit unsigned integer
    # [. u) @2 b: O0 D: j$ _/ n- K* bint16        16-bit signed integer2 m* u5 h. n& k0 Q7 c
    uint16        16-bit unsigned integer) c* k* B! y, }
    int32        32-bit signed integer0 \* @( @9 o) i
    uint32        32-bit unsigned integer; W( N) F. B$ f/ Y: K! A
    int64        64-bit signed integer
      n7 i: H* M: p3 w4 Ruint64        64-bit unsigned integer
    $ m. B: ?: x5 e8 J* n1 n" `: `single        single precision numerical data
    9 |  O- ^$ d3 Ndouble        double precision numerical data( l0 r+ {$ L# Q
    logical        logical values of 1 or 0, represent true and false respectively
      X: X6 ~$ V% F1 D4 r* tchar        character data (strings are stored as vector of characters)
    * @* K& T. l/ c  C9 e, K# \cell array        array of indexed cells, each capable of storing an array of a different dimension and data type! s) J: i* D8 H0 H
    structure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type
    ! M( T$ d& J+ B$ F4 L1 _/ r  P) Cfunction handle        yiibaier to a function8 l) s* w" m  O$ x! T
    user classes        objects constructed from a user-defined class3 o* h& F6 x/ _$ L
    java classes        objects constructed from a Java class8 M% {% b: b" f2 h
    例子8 y# x8 K  O$ K3 L  _2 ~
    ! Y% j% d& L( \! {, G" G4 U, A
    创建一个脚本文件,用下面的代码:+ P! e/ S: K6 {: F  r- q

    7 c+ @" ~$ ~4 t str = 'Hello World!'3 x# ]& ?- P: x0 p( N+ _4 `
    n = 2345
    : m, D9 @/ _; Q" M1 ^9 H1 qd = double(n)
    % W( h0 a* \6 {" {+ q9 {un = uint32(789.50)
    , e! @/ v% x! j9 E" ]rn = 5678.923470 g3 }; Y2 O2 }. t4 z- H9 G
    c = int32(rn)5 k3 @; W. r- e0 y& ?9 Y
    上面的代码编译和执行时,它会产生以下结果:, V* @  S9 Y/ ]  R* h* k
    & m$ |' \9 N7 m1 x7 q
    str =! x! Z1 f( ^; E0 N; a
    Hello World!
    2 y0 B! _$ f- T! f  P6 in =# h, A- T4 J' U$ y% b
       2345) u, B8 G9 I8 L6 s: {8 n- z
    d =0 t! D: G! }1 ?& f
       2345
    9 w8 ^% t3 B9 W3 i; yun =, i8 ^+ z9 a% i$ L! i
       790
    3 y/ p6 r" ?4 E  ^. s& drn =0 n( Y, h" G9 ~! J9 w  b
       5.6789e+03  [& r9 Z8 F9 d" b. `9 g
    c =) _: [' {( b* R5 l
       5679
    + n) {5 z! {. L0 a1 k' u/ v数据类型转换% j2 V% j9 B0 D9 E& p

    1 G5 G# U9 @. t/ B+ `MATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:* m& Q+ Y' u# h) B

    6 X  I" L4 S/ d2 q0 f函数        目的/作用
    4 p2 ~- Q$ g; }: z4 T9 j( Y2 achar        Convert to character array (string)$ T+ G( f( t3 Q8 y1 w1 ~; c6 m3 o
    int2str        Convert integer data to string' V, N# n5 e  r& ~/ A' _3 Q  @
    mat2str        Convert matrix to string
    : {6 u! r0 D% Y7 I* |- Lnum2str        Convert number to string5 ?1 `2 T) _  m/ J9 a  b: g
    str2double        Convert string to double-precision value+ o; H/ D+ w% h- |3 G! _  I+ n( h
    str2num        Convert string to number& y+ e7 @: q1 L/ v0 l! A' a
    native2unicode        Convert numeric bytes to Unicode characters" d4 L0 |4 l6 m" ?0 j; Z2 {) V: [
    unicode2native        Convert Unicode characters to numeric bytes
    * B/ B* ]3 L, rbase2dec        Convert base N number string to decimal number
    ' i" {* K+ S3 ybin2dec        Convert binary number string to decimal number
    - g/ u9 m# r4 i8 l4 G% M4 Ydec2base        Convert decimal to base N number in string
    4 l. U  A/ V) p+ n* o( v1 K' ?8 O  `dec2bin        Convert decimal to binary number in string
    5 H1 P/ G8 `( }$ T8 Mdec2hex        Convert decimal to hexadecimal number in string7 J7 [8 Z! ^' {- p7 Z7 B
    hex2dec        Convert hexadecimal number string to decimal number
    . u2 L. J$ d) _1 o) ihex2num        Convert hexadecimal number string to double-precision number0 i3 _1 I7 G9 F( h, i* d- h
    num2hex        Convert singles and doubles to IEEE hexadecimal strings
    7 n2 P) Y0 }* H- o, }cell2mat        Convert cell array to numeric array
    - n4 [/ X, _" ]3 ]( i  Ycell2struct        Convert cell array to structure array/ {9 @9 J2 h8 Y& T4 ?. C) L
    cellstr        Create cell array of strings from character array
    0 ~, M" C& ]( N, f9 g8 n/ Xmat2cell        Convert array to cell array with potentially different sized cells
    % F2 G6 w( ^  G) s; h. m0 i' Nnum2cell        Convert array to cell array with consistently sized cells0 g& A" S2 ~6 z0 P8 J* Q9 Z
    struct2cell        Convert structure to cell array% Y; U1 a& w$ J" j. I
    测定的数据类型
    + a5 e4 @% M. o8 v: q) N& I- V
    , J' A/ w  ?. S1 R: C5 p3 ^8 }MATLAB 提供各种函数标识数据类型的变量。" m0 Q; e7 J4 _5 o3 Y0 d9 N
    ) }/ K' z/ Y0 N  p
    下表提供了确定一个变量的数据类型的函数:% I# ~" Z2 p1 S" g3 ]
    8 f4 I+ H( b; p) X
    函数        目的/作用
    ) @) O- {& f1 m3 T( |2 I- A1 W! Mis        Detect state
    9 Z" i+ v& V4 g1 ~5 r$ B) bisa        Determine if input is object of specified class
    + F7 w- a. J% Siscell        Determine whether input is cell array% Z/ L0 o; X3 K8 }6 d' \9 K/ Z
    iscellstr        Determine whether input is cell array of strings
    7 f$ T' F6 Y8 J# n; kischar        Determine whether item is character array5 Q: P9 ?) v7 ]# |0 b
    isfield        Determine whether input is structure array field
    : X+ x& [& ^/ G& e, ]8 h7 ^isfloat        Determine if input is floating-yiibai array3 W8 x% Y* j6 i# p9 h
    ishghandle        True for Handle Graphics object handles+ w- B. J% R+ i
    isinteger        Determine if input is integer array
    2 B6 x! b. t/ Misjava        Determine if input is Java object
    6 F8 A% ?( |( t+ ^2 xislogical        Determine if input is logical array
    , P% ]: G/ q  S& w6 B. T' wisnumeric        Determine if input is numeric array
      `+ U  ?5 ^" L: p9 Nisobject        Determine if input is MATLAB object9 j" X. k' i  i  Z0 D! D! T
    isreal        Check if input is real array
    ( Q! m- s) a& j- u; ?isscalar        Determine whether input is scalar
    . N+ z! A: M6 R# ~, F9 @isstr        Determine whether input is character array
    6 u" ~3 I# H  aisstruct        Determine whether input is structure array
    / `1 c4 A* W! e% W! f9 s- Pisvector        Determine whether input is vector
    4 p' t1 ^, J2 K. Xclass        Determine class of object; P, O% O) k, S3 H3 Q! q5 P
    validateattributes        Check validity of array7 }+ J6 U  F. ]( }. a) ?/ D4 Q
    whos        List variables in workspace, with sizes and types# _4 t/ Y4 d# C& q9 S
    例子
    $ }, f: E2 T+ s, r& t) T& f/ i+ c4 a" b6 b& L7 a" L. r) ~
    创建一个脚本文件,用下面的代码:
    ( [2 `  |6 n. H' p+ N  i9 W5 Q8 |5 N9 i9 a* f
    x = 3
    4 n6 \) o' o9 h8 O- w7 M# oisinteger(x)% L2 w( W$ k: w7 M4 o+ _. S1 F
    isfloat(x)
    - D! @1 Y# Q9 d6 B3 |7 qisvector(x)
    ' K+ o' W/ X; Sisscalar(x)% v+ F" L. Z# v- {* @3 J+ o" N
    isnumeric(x)! |5 i3 z# \4 g) {, w: x
      H, L2 \* z! P/ _3 J$ q
    x = 23.540 w6 f2 v* r- ]' C/ l: g, A7 k) q
    isinteger(x)
    ) @( l# e+ v1 ]: x6 Zisfloat(x)4 ?% m6 Q2 L/ q5 C1 y7 A8 ^
    isvector(x)1 X: d% l/ o3 c) p1 B7 S& J3 ^
    isscalar(x)
    * j' O* u/ |- K4 ]( Z* |1 _isnumeric(x)9 w0 @. ?; U! P  l  D( g3 }

    + [! q; W2 l7 I4 Wx = [1 2 3]- o' w0 p: R4 V# T' J; ]' R/ \, @
    isinteger(x)" \: }* q+ n7 f3 u/ d$ G5 J' |
    isfloat(x)
    + o' `  Q5 F& b4 h/ Q3 ?isvector(x)
    $ s' F; ?/ K% bisscalar(x)
    / ~" H% L( i3 q* }& ~# q3 Y# U. w) P7 @, m
    x = 'Hello'9 {5 _1 z$ d' I  e0 N
    isinteger(x)- U$ K9 u* E9 C& e) M6 d
    isfloat(x)
    " s; w" v" ~& Gisvector(x)
    + o4 e- @# H4 Pisscalar(x)
    0 E; n- a8 n) `+ d- {8 m7 `isnumeric(x)
      L; R& @( Z& w/ Z( n; r! ^) |, C% v+ r当运行该文件,它会产生以下结果:$ y" O+ O' D4 U
    % M* h# C+ M- P, z; w
    x =
    9 D  o7 Y" S2 B) ^5 `, l! c* L     32 z6 {) r4 ^+ m0 F2 ^& ~
    ans =
    ! L: N$ n+ l( A. G3 \9 M$ q     02 {& b) D/ }1 c4 g! o( R: I* v
    ans =
    ; ?- ^1 D5 ~, N2 H8 D! E9 E; N2 P     15 s1 s3 ^$ a2 a7 E3 T' L& I0 [- C
    ans =
    + D' K/ J* Z8 B5 W% |0 Z     1
    ' @! x2 ?1 v/ j4 d" X& zans =. K2 {9 ^' t7 L0 _- ]1 M. P. p$ ?
         1
    2 A% K  ]/ \2 ?# {, Yans =
    # L) U% V0 Q9 ]! t, [     1
    + E, K6 [! z9 K! Y* ^5 Xx =
    . D8 Z5 p: l0 p. i0 o+ t   23.5400
    / N: `# B2 _* C6 i, x' eans =
    ( Q1 R  `% i7 c' D     0
    & @$ i  _$ q9 j) j7 O' H- d$ bans =
    5 c0 B8 `6 `% [1 j# |2 Q     19 v( `# Q9 R9 O+ H  N; G
    ans =
    1 D# ~4 Q2 ]8 [( e% n( L$ W     1
    ( }3 }" J1 p- i1 cans =
    $ k. H8 f& p: C% x! p     1
    $ P2 f4 G, B7 |: k3 Z0 dans =& }2 @2 G$ S6 S6 W
         1
    . W' x* R  D. T4 {. zx =
    8 S3 m) I+ {) q     1     2     3
    / m8 X' j/ ]( ?2 F9 f9 wans =
    9 u8 W; t% V4 Y+ A. i# q- K     0. e4 z- S4 C3 L1 E8 _
    ans =! w0 q5 k  {$ ]. }
         1+ b- T$ \/ p2 c  x+ L  r, s+ X
    ans =
    8 q  }# z% ]3 C0 i* N8 d; \     1: m$ m6 w" x3 k( O
    ans =
    # ^+ J4 T* z4 K6 Q; g     07 H3 Y# B: Z9 p& U) c
    x =' l  G. q, J5 R
    Hello
    - F+ @& \' b6 rans =9 g' s  ^9 r# y. _
         01 l$ P4 O" B8 W7 k
    ans =0 H$ p7 j+ C. a+ u8 \! L
         0; V* e9 ~: c5 R3 L. h) o
    ans =2 {. a4 ]. r* p& _  V1 O
         18 {, v9 S& O$ Z4 v
    ans =
    " T+ i! S5 z" P8 K9 d/ ?# x8 G     04 u7 ], w6 q2 \9 V1 D# S
    ans =
    # ^( j; g4 l5 D0 `     0% J* k: L2 t* ?. o+ f7 @
    $ ~1 T5 G- \) j$ J" F
    ————————————————7 j9 ^7 k% J, Z, \
    版权声明:本文为CSDN博主「Phil__ming」的原创文章。
    1 }1 ?' C/ X+ F$ \- C* C1 ]原文链接:https://blog.csdn.net/Poseidon__ming/article/details/750925753 B: {  v% P  R. @' y# c$ b# j0 K

    : S( |$ ^4 A- Y
    8 E+ B/ Y3 W% L, t0 Q- T3 t
    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 04:01 , Processed in 1.242622 second(s), 57 queries .

    回顶部