QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3392|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。
    - R4 ]# F- }% ^) ]( F  Q6 X& Z
    ' Z, c( t; H5 C* L; t. C1 r* o如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。
    7 Q, ?) c1 y# e3 W
    - o* [! P) y" r% }例如,; T8 V# C3 n& v; f

    + @7 P0 S. i) F5 hTotal = 42
    3 h/ K$ X! W$ v/ P上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。0 \: y: ~# X. H
    ! ~! y6 ?, v. k- y! C* ]9 R
    MATLAB中可用的数据类型% Z0 e: f1 l% t5 L* H3 K2 `

    . Y+ k" R& x# V4 N$ rMATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。
    " ]) I+ S! h/ f3 n$ K) X# ^8 p' \& d- ]' m: G6 G3 U6 J- [
    下表显示了在 MATLAB 中最常用的数据类型:$ ?  q  G! ?. m3 F. e

    . I& h9 g: e: X数据类型        描述
    0 Y6 Z* ]3 C4 s% Y  gint8        8-bit signed integer
    - P: a: N6 G8 |: [; {uint8        8-bit unsigned integer
    - G' r- \$ @* Q9 ]9 xint16        16-bit signed integer
    & @( X7 f+ Y; w( Y8 xuint16        16-bit unsigned integer7 Q  l4 S/ m- @
    int32        32-bit signed integer8 ~$ U5 ~; b- B( v
    uint32        32-bit unsigned integer. Y) ?" j( R! S; _1 H& o" t) h
    int64        64-bit signed integer$ o& `) W, |% U& S
    uint64        64-bit unsigned integer
    9 {6 n6 r( p0 x$ J1 Jsingle        single precision numerical data2 c8 P4 _/ }0 a
    double        double precision numerical data0 z6 l4 [. {! R8 J
    logical        logical values of 1 or 0, represent true and false respectively
    4 ?7 U/ f- |  e* }char        character data (strings are stored as vector of characters)! H5 g# @: ~+ W" q
    cell array        array of indexed cells, each capable of storing an array of a different dimension and data type+ g7 u: o6 ^; j  F
    structure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type3 s" j" f) D, v& `, |$ y# W5 G4 ]* U
    function handle        yiibaier to a function% z: M, G) l( V
    user classes        objects constructed from a user-defined class8 b, ]$ @5 k, t7 G' @
    java classes        objects constructed from a Java class
    % i) \8 C# p- i: X9 c例子5 ~+ G6 i1 d& X4 g
    ! A" ~) A8 D' t: f" a9 i
    创建一个脚本文件,用下面的代码:
    9 c: M' |3 E+ N8 O- i* k7 h9 ], K# |9 M
    str = 'Hello World!'
    + Q- ]0 [5 O/ S/ rn = 23452 H5 V5 k8 c3 C) ~$ f
    d = double(n)# T( N+ ?# i: D  Q
    un = uint32(789.50)
      ]6 v  @8 l& C# e$ p* H3 F4 crn = 5678.923471 W, X  a; E0 H  F! U
    c = int32(rn)
    ! H  O  W' }; ]上面的代码编译和执行时,它会产生以下结果:
    : W( e) m- [: Z. Z" o* }4 \) D' c; o; K5 Q" X- Q: k# n% Y( R
    str =8 M) j/ ~4 z7 C: A9 ^- |' H
    Hello World!. u& B, Z' k* x( y4 A  `
    n =8 \7 \4 {, o4 k. N# T
       2345/ o( ~, M2 c( c/ O4 q
    d =
    5 h; e6 W5 S/ h6 d; [7 U   2345& ~' R5 [1 N+ B! `$ T9 d- D% `
    un =
    / |. ^' ]4 A  }/ y( q9 `   790
    5 M6 G- C; i" p/ Hrn =
    3 _$ F* G6 _& H: Q) y( b   5.6789e+03* N. g# u+ W0 @% J
    c =* b7 b" g7 F+ V' C' S. {4 w
       5679
    1 }. Q1 \1 J% `& D! f: A数据类型转换
      g) @( x! z( [# i( g
    7 K7 f1 y! ?  PMATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:3 I- z/ W7 o) M7 h9 k
    5 x8 S: D9 x) Q4 f1 X. ~
    函数        目的/作用3 f$ h0 ^) P( [. ?3 E/ ?5 b" O
    char        Convert to character array (string)* p3 e, R" V- ~5 I3 \
    int2str        Convert integer data to string! U" T& ~7 g! @5 W+ F
    mat2str        Convert matrix to string3 ^7 Z! a4 }, \" R) K- j+ r
    num2str        Convert number to string1 D- J: Q. F* Z. N- t% p( G
    str2double        Convert string to double-precision value
    & [  x* Z' x9 x) ]- Cstr2num        Convert string to number6 C8 s0 x+ _: ~4 c/ F& i/ X* |; `! I
    native2unicode        Convert numeric bytes to Unicode characters
    : X# _% D/ S6 eunicode2native        Convert Unicode characters to numeric bytes" p* m- ]$ r2 P1 V( }: P3 W6 ]
    base2dec        Convert base N number string to decimal number
    : r$ w) B% ]& O7 v- Z1 o5 x- Xbin2dec        Convert binary number string to decimal number) b+ f/ P" W$ T  u/ y
    dec2base        Convert decimal to base N number in string0 w/ W& A/ w' W$ P" h# X
    dec2bin        Convert decimal to binary number in string/ j. N; C2 D4 `8 Z0 X; `% b1 ~
    dec2hex        Convert decimal to hexadecimal number in string
    5 K: S7 D& h3 p0 p, U* ~( }hex2dec        Convert hexadecimal number string to decimal number
    4 W7 \& x6 Q' W3 t( Y4 Shex2num        Convert hexadecimal number string to double-precision number8 A! g8 \3 ^% G0 P2 h1 s) w8 p
    num2hex        Convert singles and doubles to IEEE hexadecimal strings
    , x2 v% E: @7 P  T7 y8 scell2mat        Convert cell array to numeric array: X  c# s) c" D3 A
    cell2struct        Convert cell array to structure array
    $ _" a/ a7 A; {3 ?$ {+ P( _cellstr        Create cell array of strings from character array
    # m$ ]  p3 j" G  [9 L& Dmat2cell        Convert array to cell array with potentially different sized cells2 T+ H% B9 K2 V# p
    num2cell        Convert array to cell array with consistently sized cells
    ! b/ x3 s4 g+ l( n+ Kstruct2cell        Convert structure to cell array8 E) x. \! c3 `
    测定的数据类型
    7 s, h, q# V* ^5 d% W
    ! v1 E3 x* l* aMATLAB 提供各种函数标识数据类型的变量。, r0 B/ b! D/ |2 R- n! c, s- C

    ! U, t" `! Z; V" ^; F下表提供了确定一个变量的数据类型的函数:! O) q; Z6 n  O' ^
    9 [) ~) [) P" U2 C8 h  E
    函数        目的/作用1 G/ R% U$ ^2 e! S
    is        Detect state2 Z! _2 m% X9 U3 l' c  V
    isa        Determine if input is object of specified class9 T$ r* k. ~8 o$ z; `
    iscell        Determine whether input is cell array; @) T, i5 ?/ P3 o8 _
    iscellstr        Determine whether input is cell array of strings! \3 [' A( E! P- k( a9 {
    ischar        Determine whether item is character array1 F* r8 Y# K) k% C" y  A/ F
    isfield        Determine whether input is structure array field
    1 C/ R" K7 j$ Misfloat        Determine if input is floating-yiibai array
    6 v3 L3 h! G& \/ Tishghandle        True for Handle Graphics object handles
      e! K4 |/ w2 H- `9 `) ?: A  Gisinteger        Determine if input is integer array: ]0 |- o0 |% f. m/ ]4 U
    isjava        Determine if input is Java object3 ?; H. Z) C& x3 Z1 ?
    islogical        Determine if input is logical array
    2 O$ q7 j1 g" o$ z- G/ I% P1 e3 jisnumeric        Determine if input is numeric array1 Q' Z7 H  V+ \0 M( r* C- E
    isobject        Determine if input is MATLAB object
    4 E" H. H/ S9 j. k1 p! f3 eisreal        Check if input is real array7 j& d* [% v/ m! [
    isscalar        Determine whether input is scalar- Z; O3 ?6 i* `+ W# ]3 m
    isstr        Determine whether input is character array
    ' x6 L& E+ W" \2 [/ J/ N* Iisstruct        Determine whether input is structure array
    ) X, P, R/ ^' \' O" B" c4 F# |  \isvector        Determine whether input is vector5 N1 d' B( F! M$ B& G2 b+ C& ^
    class        Determine class of object
    $ \7 d# w  h$ s4 m7 Hvalidateattributes        Check validity of array- b: R( r) Z' o$ v
    whos        List variables in workspace, with sizes and types: |) e3 b( e" D! G9 T
    例子
    1 f7 r* n3 L% r' t. h0 {5 {% z9 ]. O9 q* X$ t3 _
    创建一个脚本文件,用下面的代码:
    2 M6 A2 C! F: s8 F' B6 o) `) @, q; z- d' X
    x = 3
      L2 ]" s: O- ~9 n' Disinteger(x)7 {9 N8 ^5 B9 i' u, ?4 g
    isfloat(x). M" ?/ w0 m% X: G0 \
    isvector(x)) M+ z3 k/ k+ p! }$ t( B0 f
    isscalar(x)
    9 `1 n# O" Y6 }isnumeric(x)
    # t1 h- X& E# s4 h) ~# U' D
    9 [+ s  j6 i0 G: f. ^x = 23.54
    8 R% r% `! S1 ~7 x/ sisinteger(x)7 J- i  w4 B( q4 ]! N2 w' m- c$ y/ g
    isfloat(x)2 c1 u$ M# b% u/ {9 N7 D# y
    isvector(x)( B7 F' K, {( O  Y/ ]9 M
    isscalar(x)
    . G5 u5 Y% j+ h% B2 u: k0 Y( ~isnumeric(x)
    ' ^* o" X  A) ^& u4 D2 i6 n2 p1 J8 _0 ]8 B$ T
    x = [1 2 3], R0 D+ L! e; F1 p* {, k
    isinteger(x)
    ; j/ i9 V( b/ b( b+ B; {isfloat(x)
    5 K" l7 p2 l& z8 i5 Lisvector(x)
    + P% y3 L, J& ^* T- Yisscalar(x)
    + U& x4 c6 c% }6 ?* Y
    ! u4 @8 L  j" F+ R- |x = 'Hello'/ _+ }1 R+ M' a2 V7 v% A6 v& o6 P
    isinteger(x)! u5 {: ?; l3 _' V* d
    isfloat(x)
    % {' l4 u4 @+ L* P7 O# g& ]. ?isvector(x)
    % P" \' v9 {) ?- ^! f# K! u3 ?$ E, eisscalar(x)
    , k$ s, q6 z9 d; I- |  Nisnumeric(x)' j- B) q( s. s- A) F
    当运行该文件,它会产生以下结果:* E5 S2 S. N9 B* E% T6 J3 l9 i& a

    + P+ B1 M# z' Z' ?7 _x =
    6 n# l7 M/ h; u$ R! V     3
    0 s  ~. q% `9 ^ans =
    $ Z" `0 R: t6 {     03 J7 u' t7 Z0 u: d0 R
    ans =
    ( @! m2 `, L* J- d5 j- A     1, N& Y% u$ ^- Z6 ?8 E
    ans =+ m, p+ e2 K% A' \6 ~( o# H( v
         1
    * D& A3 {+ @0 e7 Bans =+ ~* @4 h; X: E+ @
         1
    & x& G* j. s1 F3 h  [& i' {( qans =
    / N5 Z3 d5 s$ i- L     1; z- l7 V( i0 ^. ]- O# Q+ N1 n
    x =. W* Q9 R0 i, C' ]) v
       23.5400
    $ z. q7 A/ L2 N5 L; aans =
    8 @- t: b/ V3 D% c# n5 i     0* u( ^' a, F0 u6 N; J6 |
    ans =
    . _+ p' q5 i9 r, o( |. ]( p     1
    5 x2 _: Y$ U( N! z. Wans =
    * q$ z/ q2 E  h2 @$ a     11 f5 Y3 g% _' U% J
    ans =
    $ X" }: Y' w# N     1
    . O7 K7 ?: w! M* d, Mans =
    % S, \7 A3 ^& ~3 o  }2 D4 {* Q     1+ R# [- n" h. N) c$ {
    x =
    ; v0 r5 G) d8 z) Q$ ?     1     2     3
    9 e6 X& H- t6 r0 E: qans =' L# m) Q1 C  H! @0 \) S" i; v( v
         0' a0 ~2 u& X0 k: |0 v$ R
    ans =
    + n8 V3 S$ R# D/ B0 T     1
    & w! W3 m! R2 @: J' h8 l* jans =
    - C2 W: F/ H( ~$ G% q( J1 S     1# c5 b0 m4 H  z! }
    ans =
    ! g& U# F# i7 c, @     0
    , T% p$ L# v( Ex =
      x: H! X+ E/ WHello9 J! |, R( t; x: A' g3 i$ e6 z
    ans =
    ) J# l# ~$ t& H, k1 k% G* j, F     0
    $ @# L# a& D# m7 a1 A" lans =
    . ^' w% D  B3 N) ^8 t+ A8 P1 P     0
    ! v' I; `1 c1 X1 W& Oans =% F. L& s0 k$ `0 g5 l. |% f4 w
         1
    . W; i3 a7 q  F0 U$ t2 Y! [ans =( F7 i$ ?4 J; q
         0  ~& ?, r7 Z& X! j* R2 A
    ans =  Z* E* q$ Z' G; w0 G/ T
         0& _6 w& w/ g( l' {8 @' {
    $ r, O9 I  n9 `  y% u
    ————————————————
    8 y+ o- Z, R8 |( t$ h" \; ?版权声明:本文为CSDN博主「Phil__ming」的原创文章。; ~) s& X# m0 S9 }
    原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575
    $ F: Y" _9 u. |) g; \  }
    * q4 E; u/ x9 C0 A8 g
    0 m6 {# A& D( r* Q2 z
    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-6-13 06:02 , Processed in 0.461305 second(s), 57 queries .

    回顶部