QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3127|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。
    & `$ j" N  ~% K$ `( f/ |" _2 \6 P8 ~3 @
    如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。  W) K- Y( w( ]+ |: k% `# M7 G
    " V- J$ u7 U1 X" b! J4 Y2 l4 m# u/ A0 l
    例如,) O! K  F8 Z) O" u7 D0 m7 I
    0 h/ v1 @  `) ^+ K  J5 b
    Total = 42" u, p2 U% Y" ]$ f) k! g
    上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。0 J& I8 u) Q5 M  B3 ~) d

    ! W: H) J$ {2 s3 \; w& S0 t' FMATLAB中可用的数据类型# Y+ \% r% q$ I* w

    9 E5 _0 o+ {0 N) Q7 VMATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。
    4 X/ Y' W( Y% o+ }
    ' c1 k* w$ i6 e" Q( q下表显示了在 MATLAB 中最常用的数据类型:# M: f0 t, Q2 x, A

    5 B/ p+ d! f! U) h数据类型        描述* p& J+ q. W* n- ~& C
    int8        8-bit signed integer
    . f4 X; h( |7 Cuint8        8-bit unsigned integer/ `' A: S9 @4 ?* s: i1 l
    int16        16-bit signed integer5 x" h9 C% T" v, G) p/ ]. o
    uint16        16-bit unsigned integer
    3 @' U1 M8 b& ~! a, C" B! j8 jint32        32-bit signed integer* T0 o/ U% e: e8 A, N$ }5 y) V
    uint32        32-bit unsigned integer
      x/ j. ?9 g7 r. e9 |, e# kint64        64-bit signed integer
    3 m6 D. _* u, J7 J: K& K# `; wuint64        64-bit unsigned integer
    8 \* X! E8 L% H$ \: fsingle        single precision numerical data& n$ D: F1 C) i
    double        double precision numerical data# Y. U% u  x8 d1 O
    logical        logical values of 1 or 0, represent true and false respectively5 P0 w& T( W/ f% Y- l4 p
    char        character data (strings are stored as vector of characters)- L: ?- T; f* Q6 t& H; }
    cell array        array of indexed cells, each capable of storing an array of a different dimension and data type8 ~8 S1 O# ]( x  J9 N3 l# n
    structure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type1 t: @) T# w5 _) e! ~% m' ~1 d  s5 W
    function handle        yiibaier to a function1 N2 e1 ^3 b. Q$ j$ H
    user classes        objects constructed from a user-defined class
    5 @1 f' w: g% d- G/ B1 Tjava classes        objects constructed from a Java class& T% b  q2 f4 [* D
    例子
    . B5 Y$ L7 t. ?) r
    5 @( l" s4 f( A" }创建一个脚本文件,用下面的代码:
    ; P1 X$ X" i' d: V2 W: n3 \. m9 U, u
    str = 'Hello World!'/ t% q" v5 o6 `4 o
    n = 2345
    / t+ i' y  {- X) ?  nd = double(n). ~4 r& [. o( v( X' G
    un = uint32(789.50)
    0 w' x! `; N2 }# ern = 5678.92347
    3 n# E0 E, j( }c = int32(rn)
    1 B# b! e( m. B  C2 w5 F1 ^/ V上面的代码编译和执行时,它会产生以下结果:: {* {% t* t0 ~
    % R. j) ^$ \0 @. k1 P
    str =
    " ]1 f" |% x1 ]" q( IHello World!5 i" n7 i* @' O( N  L4 V* U
    n =! Q, ?' I: l0 K& j
       2345) [9 G& {# J- x  R
    d =
    " u! Y# @  |. J  l5 G   2345, E! w, N$ |6 H: j
    un =
    * P; m& e1 A: t) G0 z1 w0 K   790" g1 O1 ?% S. z( }  R
    rn =6 N% Y; ]- n6 B$ C% b
       5.6789e+039 L, d" C, L; k3 X9 _+ q
    c =) p  f, }8 n8 p. j& V6 ~7 Q
       5679
    ( ]) j, ]- U; @8 O$ }  y+ }/ [数据类型转换( U1 c* c6 q) ^" `- Z

    3 Z3 b4 A$ u/ u& D6 F5 `MATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:
    * K# }# M( a+ T; |4 E6 }. [
    7 A, P" k. ?: K函数        目的/作用$ m" |) {6 S0 u9 w5 e. z
    char        Convert to character array (string)
    - e6 {+ U4 {8 R$ `8 Kint2str        Convert integer data to string1 ?& R* `( y" T* b/ B
    mat2str        Convert matrix to string- y. |4 }+ Y* [
    num2str        Convert number to string# T) P6 v8 G4 _* I# P5 {
    str2double        Convert string to double-precision value8 R0 H  K( o. s" [$ G( H3 X
    str2num        Convert string to number  j9 g8 Z9 ^; ?; k, Z
    native2unicode        Convert numeric bytes to Unicode characters
    - I( k# T5 n' H; r# r5 Xunicode2native        Convert Unicode characters to numeric bytes
    : J  v( Z0 T4 g9 Zbase2dec        Convert base N number string to decimal number
    ) g8 @0 x' K, d& {8 l2 c, _% ibin2dec        Convert binary number string to decimal number- m3 R5 E; z* s7 ~, j6 R
    dec2base        Convert decimal to base N number in string- C& w$ ?! P1 O, e4 z0 X/ t; A, n  A
    dec2bin        Convert decimal to binary number in string
    9 G/ I, K9 F' }/ xdec2hex        Convert decimal to hexadecimal number in string3 p6 q4 k+ F9 j8 b, @
    hex2dec        Convert hexadecimal number string to decimal number6 j4 ]9 s- }5 k! i4 q
    hex2num        Convert hexadecimal number string to double-precision number8 W; P# L$ l/ [0 b
    num2hex        Convert singles and doubles to IEEE hexadecimal strings
    , _2 _% m8 c3 n9 i( n# s5 ?cell2mat        Convert cell array to numeric array" Z! I: D  V+ K+ E- K
    cell2struct        Convert cell array to structure array- f' |! L, I1 Y0 r
    cellstr        Create cell array of strings from character array
    9 _; o- y: ]- {. F7 }6 I0 {) tmat2cell        Convert array to cell array with potentially different sized cells0 ~, O* B- o, K1 z% I
    num2cell        Convert array to cell array with consistently sized cells
    / T) P5 I- \' ustruct2cell        Convert structure to cell array
    : l' V7 M- |1 a3 o( s测定的数据类型
    6 w( [- c# t# Y! a/ w9 Z5 a; c+ ?' A" @; Y9 ^+ j- w% [% U
    MATLAB 提供各种函数标识数据类型的变量。- m0 m1 M( S& j/ d( q

    0 X4 ]5 N+ ?  o0 _6 h下表提供了确定一个变量的数据类型的函数:8 O9 i, ^8 U1 Y. n, q/ T
    % T! X6 H$ [1 B, [) M; O
    函数        目的/作用
      w( O% r0 n% h( N9 Qis        Detect state* t/ ~  y' K0 u- {! J/ r
    isa        Determine if input is object of specified class$ |$ u" z9 N2 v- [+ i1 a. J6 a" o5 B
    iscell        Determine whether input is cell array
    3 c9 z3 V) T3 E# T0 Wiscellstr        Determine whether input is cell array of strings: a! W" N- P/ j0 A/ L- O) [( M+ b
    ischar        Determine whether item is character array& R% T; Y" X# r2 A7 K! p" b
    isfield        Determine whether input is structure array field3 k1 X- G/ m+ f% N
    isfloat        Determine if input is floating-yiibai array
    ! o0 d; m/ t4 ~8 Nishghandle        True for Handle Graphics object handles* Y0 _% |- N/ y" Y3 l5 I
    isinteger        Determine if input is integer array
      Z) P6 Q1 U( L$ @# z6 P6 Q, n3 c* bisjava        Determine if input is Java object
      P9 s9 S/ J7 e0 j- R* E2 vislogical        Determine if input is logical array
    4 K- @3 Q: r; o4 S) |1 G+ J3 Wisnumeric        Determine if input is numeric array' P3 u& d% ~& C  R. t
    isobject        Determine if input is MATLAB object6 k2 N+ }! W; t) V3 v0 K
    isreal        Check if input is real array9 q# p8 p4 T" w9 D8 V1 f; j
    isscalar        Determine whether input is scalar- `7 ]1 E7 W. I: K
    isstr        Determine whether input is character array4 P% Y" B5 C% m& w# e8 x
    isstruct        Determine whether input is structure array2 x5 `1 r' s4 v# |8 n
    isvector        Determine whether input is vector
    " [2 v( x0 h8 p+ q2 Gclass        Determine class of object
    " @* I  e  U! B/ D3 n0 d) xvalidateattributes        Check validity of array2 D9 v7 [$ j. ?: j6 S; @6 u
    whos        List variables in workspace, with sizes and types! B+ Q; f1 s/ [8 Y, z
    例子
    # X1 [6 ?1 ]1 X
    / K$ Z5 [- p( l% J创建一个脚本文件,用下面的代码:
    - F+ `9 p" [; D9 i
    # n2 l! t6 h1 _* @1 t' t5 o% t: nx = 34 r7 t. d% H, c2 D
    isinteger(x)
    2 I7 ]" G! X% z* Y4 wisfloat(x)( i1 j. {4 w! d" K' L
    isvector(x)
    0 p+ o, J. C! b' H" x  r( xisscalar(x)4 N& Y3 D% d0 O9 }
    isnumeric(x)
    - c" O( {/ L3 h! f! o. @/ I3 \6 L! [' [6 T( W
    x = 23.54
    & i) o4 L/ T# p) {isinteger(x)
    6 m7 o0 Q9 P5 y( |  e2 risfloat(x)
    ' z, s* d, t, f) C% _$ oisvector(x)
    ) q9 U# d6 ^+ I7 kisscalar(x)
    & h+ q4 m8 u( B/ I7 }isnumeric(x)
    & z# G) Z/ b) e% c- ?4 v/ F% J2 N8 ]
    x = [1 2 3]( O0 [7 h9 x) v6 d' i
    isinteger(x)
    1 `+ ^; h. A1 I) g' }3 [, A; |) sisfloat(x)9 J8 b" W8 O% H# \, Z
    isvector(x)" Z9 U+ g- Q! u/ z1 v- T
    isscalar(x)
    * O, e( z6 m, f4 K2 n7 p- O5 \1 O
    x = 'Hello'1 a6 M: X. N' u' p, ?
    isinteger(x)
    " Z) D' r7 ~9 [' {- nisfloat(x)' z8 [' P! j2 Q! _8 V
    isvector(x)! w) u, z. G  C4 K1 @6 ?
    isscalar(x)
    & H0 e0 y3 L1 q; o4 a9 I4 K6 Disnumeric(x)6 r8 I- @! |% W/ F. \
    当运行该文件,它会产生以下结果:
    6 v/ @: C0 u* Z+ H8 ^
    5 h" W$ a; B1 Y/ c' w# S( fx =  R+ n* Q- U  y1 m
         3, g  U, q5 R( F6 B; k
    ans =' C% W3 v$ b0 w' q! k; n
         06 U$ \9 q) s( W  e
    ans =
    8 ^4 B6 f. b$ k5 [/ T8 U# m     1
    / _7 T6 L+ h6 y, O5 Kans =
    6 I4 M% D; F/ J+ ?' b! ]     1
    # \5 Q0 b) c) h8 m8 e, s; ^1 Tans =6 t4 K! P  j0 x. D# x
         1
    3 y& \/ g- e3 Q( F, B" K: y0 jans =) F! b! U, f7 w0 I2 K5 ?( e
         1/ i, U6 t2 @4 p5 E# j" y/ u
    x =- }- ^; B' `/ P* x! |; M/ e
       23.5400" ?! X) @: u, ~4 A7 v0 s
    ans =: P+ a/ h- Z6 Q" q( R; @* n
         03 C- Y5 d" ?! B; _: ]' C
    ans =' {: N+ [5 P. Q( ^3 y
         1
    ) ^# U  |& p8 L" d8 h; Rans =, p3 d* {9 p# Y, j% _, A
         1) e5 t! _$ b' A4 ?4 x
    ans =4 z: D! q5 b: ]2 G
         1
    ! d2 u. \3 T* I: s& ?ans =4 ^* N$ i! R- a6 h: c# {* }' f8 U- E
         1
    % ]- V' _( Y- s; J' \8 `x =' n' P4 h  G& K0 O0 k* N5 r
         1     2     39 r" p) K/ L' E- |  u5 j2 }) S
    ans =
    1 L2 v* T) v& |1 M! o0 A; b     0! \: X' T. p; A0 q
    ans =* ^( k3 r, ~' O* B. f
         1: @& M$ U  Y1 y2 ]" p
    ans =
    % c9 M( @9 G' ?( O0 q; F3 P9 q/ \     1% o) r0 Q$ J' v- s# F5 R! z  P+ j, ?& h8 w
    ans =7 U1 H- F' n5 H8 P+ \
         0
      l/ H  u% Q. I4 b9 g7 T$ kx =
    0 B9 M1 F- j$ U$ j& HHello( ?' r. R# y1 a
    ans =- s, `7 u2 {8 g, W) u4 R
         0, h( a9 l% M0 \# R, H. {( ^
    ans =) {, N: n! Y; `# P! M- X  J3 c
         0
    # V( ?' G5 H$ x4 oans =" S$ U& e* C, @; M# q0 q- H
         14 n) f4 m+ ]5 ^! w5 v8 o- ?8 A8 q
    ans =1 V0 H" c# Q0 l& }$ i
         0' a) h/ ?. C; v. C& d' \! x% V5 T
    ans =
    : ~& u2 W* n. v+ [2 C     0
    1 f' v8 M. d4 J- W, y: I# m
    ; V/ K) X; X5 `2 [0 i# Z————————————————
    7 K3 {; F* K- I% f+ i版权声明:本文为CSDN博主「Phil__ming」的原创文章。
      j- q+ @9 T. p; [; T0 t" @原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575
    # {, I$ p* x3 B4 r. F- Q
    6 l( _" _6 V' p, _+ D6 f# C' B5 u, K; \; H
    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, 2025-7-30 21:24 , Processed in 0.368062 second(s), 56 queries .

    回顶部