QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3360|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。& I1 a; n* N$ N  z# I
    ! z; k* R+ d9 K, D) o6 i4 {. d
    如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。
    ! h6 n. F; R) s* m4 k# x* a# M% [3 d
    例如,+ B8 U! o7 k2 `: F. V
    8 l; t0 B7 }  p( E; f) i
    Total = 42" l3 h. U/ C# }: g
    上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。3 [& b) u( o$ s# R1 k) C: Y
    - ^3 B( {4 N4 F
    MATLAB中可用的数据类型, n; k! e- _, T7 y

    + E) ]" q- D6 Q9 uMATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。
    1 e3 ^+ b; k( z% H9 L. Q$ I& ~& c8 Q6 Q
    下表显示了在 MATLAB 中最常用的数据类型:
    ! O1 i8 B: _9 u) j+ |( i7 e3 G5 q1 A- H1 e$ Z1 D! r- y
    数据类型        描述
    $ ^) f& m) y5 l& f  t9 C% A3 ~int8        8-bit signed integer
    ' _3 ]4 w; O) s8 ?7 _- C, @& p6 muint8        8-bit unsigned integer! u! R0 G% k: B9 G5 L6 ^8 c
    int16        16-bit signed integer
    - |. `) Z7 L: U8 x4 [- L( Fuint16        16-bit unsigned integer3 w/ i& }6 h! j8 ?3 R
    int32        32-bit signed integer8 [1 ~0 }  B% \
    uint32        32-bit unsigned integer' @3 }0 S2 F+ e1 R& A# r
    int64        64-bit signed integer9 [/ X8 q- S) {; k0 c
    uint64        64-bit unsigned integer
    ( f( s7 d8 k0 z$ a2 ^single        single precision numerical data, s9 C) h- ^) w) H( x8 _
    double        double precision numerical data, r) o! i* z2 _3 |! A! ^* ?
    logical        logical values of 1 or 0, represent true and false respectively
    " A8 g' m$ |5 G3 f2 v0 T6 Nchar        character data (strings are stored as vector of characters)4 y5 w% G2 x) e" o, _0 N1 x3 T
    cell array        array of indexed cells, each capable of storing an array of a different dimension and data type- s$ c% r2 c. Z7 g- n7 i
    structure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type  E7 m& @' b5 k
    function handle        yiibaier to a function
    $ V; M  v; k% E  g) Y# Wuser classes        objects constructed from a user-defined class9 A+ i1 n* C3 o; _" T. W) K
    java classes        objects constructed from a Java class3 n! e3 r# S9 @/ [9 C4 J' Q
    例子) D8 n; s/ S" W+ D, C9 Q. s  i

    9 s5 w4 q4 T  x  o# i! Z创建一个脚本文件,用下面的代码:
    ' R! l- p; c! [. r  e2 Z8 w* z2 g( b9 k0 a+ @2 @1 _
    str = 'Hello World!'# K1 ~( o' n5 ~0 O! W
    n = 2345
    9 O# `: y$ ^6 t0 `* j5 ?+ }d = double(n)& O: \& H4 e+ L. _! R" q
    un = uint32(789.50)
    3 _5 [" L2 s( B- \; Wrn = 5678.92347
    ) |. S; F- E. H6 oc = int32(rn)* g* \$ t. Q) ~! W2 ?
    上面的代码编译和执行时,它会产生以下结果:
    ! u8 p0 F3 B) a$ A' `# \5 B. ^/ F4 N3 H( b1 z" h
    str =
    + l: e6 g0 w" U' X! V( c) mHello World!% P6 T& ]  S0 I% }
    n =! [% [2 K. K; M' T
       2345
    ' K5 A) F5 l: E6 R/ G+ K! od =
      I& C0 a9 m* _: ~; X, I" A# e3 j   2345$ B$ N% v; @. u; Q! I' S, L
    un =/ p3 t; f2 g/ \' m# T3 |7 o
       790
    3 w+ T) l2 R: m6 A0 w" X, Vrn =
    ) m0 m# ?) G& b4 }0 o% {# B) v9 ~   5.6789e+03
      t: h& M3 k; kc =! C5 r+ Y  C% z2 t! q- ?  x3 T/ q
       5679' U# I- n# W+ h! ~& @# q* F
    数据类型转换
    , C, e% y6 D1 O" z3 a' e. G! e& ^1 G6 F7 j6 _# }* `4 O1 V
    MATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:
    7 O" M- e7 C% O3 V. P; ~& f7 |- f' u4 b; N( \
    函数        目的/作用  g$ L, ?1 j) i9 K
    char        Convert to character array (string)3 K& m9 Q# m* m7 M
    int2str        Convert integer data to string
    : V$ e, p" d; s' Xmat2str        Convert matrix to string# Z" B4 {6 A9 M. r3 [4 h4 c
    num2str        Convert number to string
    $ p4 j2 I' ]& S. j$ L: Cstr2double        Convert string to double-precision value( v7 \% W) e" R' m' i. l: w
    str2num        Convert string to number
    1 z) w, Z0 b7 A; s8 X5 g+ @8 ?native2unicode        Convert numeric bytes to Unicode characters2 w" G! n) D. K! r7 K: ~# z1 P
    unicode2native        Convert Unicode characters to numeric bytes
    ; H% s9 f9 N* [8 @2 e9 wbase2dec        Convert base N number string to decimal number: ]$ k' r. Y, [& @
    bin2dec        Convert binary number string to decimal number
    ' d1 t; w5 J) e( [/ Hdec2base        Convert decimal to base N number in string
    ) Z& j3 N6 u: l2 _0 Tdec2bin        Convert decimal to binary number in string
    ) y# T/ T% D2 u2 ^, z$ vdec2hex        Convert decimal to hexadecimal number in string7 K- ]( }+ x: j& T' b  t8 \& U/ m
    hex2dec        Convert hexadecimal number string to decimal number1 y7 q& n" S0 z+ d
    hex2num        Convert hexadecimal number string to double-precision number
    ' K, s, X' [+ U2 `: t- E$ _2 Bnum2hex        Convert singles and doubles to IEEE hexadecimal strings
    , [% T8 c9 U6 e) i' ocell2mat        Convert cell array to numeric array" K9 M) \. y% N" r- `
    cell2struct        Convert cell array to structure array. M, b7 k0 ]+ t( }
    cellstr        Create cell array of strings from character array& s  L& P! K. U# [5 \
    mat2cell        Convert array to cell array with potentially different sized cells
    $ L: ^* f7 d0 J2 I# Hnum2cell        Convert array to cell array with consistently sized cells
    ( ?# z* O1 c, s/ ?struct2cell        Convert structure to cell array  W% r( J5 U, @: ^
    测定的数据类型
    & r1 Z9 f; \7 y5 O
    $ t6 p3 t( x' |$ q! @3 M3 @1 R0 ?, ^MATLAB 提供各种函数标识数据类型的变量。
    $ _4 F: ]. `" ~! p7 O) I$ Z! x" E4 @! W# `/ F
    下表提供了确定一个变量的数据类型的函数:. I$ U4 x* i  V# T+ {9 B! v6 W; s( o9 F
    9 e# v& K7 @' j0 C8 y: |6 H
    函数        目的/作用! X( _' `: E- q4 `5 ]
    is        Detect state
    ! R4 q  w6 ?) v) D4 Cisa        Determine if input is object of specified class
    : b/ J. l/ ^$ A) ?  M9 e+ y  a  Aiscell        Determine whether input is cell array  t* x% J/ R9 S" W" K! _' {, C- B
    iscellstr        Determine whether input is cell array of strings
    * B) z( T- w8 B/ f- Xischar        Determine whether item is character array" f6 V) z  S  D
    isfield        Determine whether input is structure array field' a1 k4 M' K1 L2 X; `
    isfloat        Determine if input is floating-yiibai array/ A  P! m' p9 l" Z, A" J- J
    ishghandle        True for Handle Graphics object handles
    $ A) y+ E' D, J( o! Y- b8 ]( Uisinteger        Determine if input is integer array/ h2 Y# a3 ]7 P- U
    isjava        Determine if input is Java object
    ' L- w* F1 @4 u: D& F1 |7 vislogical        Determine if input is logical array
    & Q$ M2 w! z/ |5 Z: [' _; C- fisnumeric        Determine if input is numeric array
    $ w: h# C, H, x6 k! m. i$ k. K/ eisobject        Determine if input is MATLAB object- K/ @; n( A" i2 A7 T1 k5 p( Y5 t. _
    isreal        Check if input is real array& D. }7 G( z! z; m4 t
    isscalar        Determine whether input is scalar
    ; f- e" N% V; s3 A6 Z0 L* R3 p7 misstr        Determine whether input is character array
    5 s/ l* v# u4 p. x+ q$ ~8 Y  H. Cisstruct        Determine whether input is structure array6 c7 Q8 ?0 Y1 F! t. r7 N0 W* Y
    isvector        Determine whether input is vector4 a& q. h7 |% m% ~9 |3 c
    class        Determine class of object( R# @& Q: g0 K0 f/ t8 X* u8 P9 u
    validateattributes        Check validity of array+ W0 U& W  B" `$ S9 F* ?
    whos        List variables in workspace, with sizes and types( W1 P2 [3 w( d: U8 x, [
    例子* X. S* H. j# Z# t# a$ g/ F6 |+ d
    6 d* U* d, x  k2 K: n; N# E* c) ?
    创建一个脚本文件,用下面的代码:
    $ |+ ?  D7 E: W* o' z9 ?4 C. A2 [' q) I% n3 Y
    x = 3  }( P2 V+ H! {$ j2 ?
    isinteger(x)
    1 y8 }  I& ^5 O! N4 R  visfloat(x)
    ! H7 F9 q4 L+ ^5 X4 s- Z8 Zisvector(x); J+ Q  q: K' I* H2 [' y
    isscalar(x)7 j: h, S* P0 @2 b2 F3 w, |) Y
    isnumeric(x)* s5 R. h2 w- P2 }$ G4 N( M4 ?  p

    $ o7 d/ w, o( j9 _9 c. Nx = 23.54
    % o, a: R. @+ Lisinteger(x)
    6 w, g) q) j; I2 f( L  O8 ]isfloat(x)
    5 n$ [/ O& M# i$ J! gisvector(x)2 W* I6 P; k( g
    isscalar(x)( d3 m& s" j2 p/ g4 s
    isnumeric(x)
    # d, x4 e* N8 e2 f: g4 V
    ' l8 T3 c3 L0 s: F! a) L: |x = [1 2 3]3 ~: g/ y. g% Y5 p/ k5 y
    isinteger(x)
    * H6 B4 r0 d) v3 j. _( ~7 gisfloat(x)
    1 h6 O/ N9 Q4 }isvector(x)7 h7 I& k& f- q3 Q7 K. `3 z
    isscalar(x)7 F% I2 Y" w6 M+ U

    $ e& N, v& u8 k, xx = 'Hello', a9 K' X  K! w- ]. {: B2 `. w
    isinteger(x)
    8 M) q4 R) {9 Qisfloat(x)9 Q6 _( q1 W# }% ^: i' |
    isvector(x). N3 N3 v9 ^" E; q
    isscalar(x)) A) m! Y* g7 Y3 _0 d1 R; ]
    isnumeric(x)
    ' s/ B# h! M9 f; R) L  s当运行该文件,它会产生以下结果:
    ( K: g$ d2 V$ b0 O
    3 w9 F) W2 W, v5 ]! q. L/ ox =2 D! H, Q$ I: F4 u4 m
         3, ~; o9 n3 d; I
    ans =
    - j6 I7 `9 d- v  ~4 \1 B" c- ]     0
    8 D. }% P8 x& F! a: [2 {ans =
    0 y% o4 }. }$ S$ V7 x+ D     1
    1 ^; j; P. h( i& p' p1 B. ~4 lans =7 C; W  f# ?$ }
         13 X; o9 g" Q' p3 y  y
    ans =- e7 ?3 H9 g8 x
         1$ b, l* E/ b. z/ D' k
    ans =4 C, l' v. A6 h' I2 H! a
         1" z. x: [6 U4 s& u+ g/ P
    x =% n. |. r& E+ X
       23.54002 ~1 I4 L- c: `( u" p; H, d
    ans =8 O' i# O8 M3 d+ c7 p
         0
    ' ?3 s% z+ @3 Jans =
    ; x5 n8 l3 N, t; }3 K     1& [5 D6 k; r0 ^3 }$ l& M* W
    ans =4 q6 k) M4 o6 T0 m: u' s* g
         1
    * b$ h) Q' F7 C, j8 O; z+ `ans =; X* a1 Z# b1 {6 H% J! I
         1
    " U" D" `$ C& b7 R' W: N  yans =
    " g7 w% B1 N4 N     1  t9 R: P$ u, b1 p' [' }
    x =. c% b+ }! D' U$ X0 y8 H0 ]4 o/ s
         1     2     3
    7 J9 E6 L' s7 v8 X/ m  Q* Dans =
    ) X# a/ g$ H; y% }     0
    4 V1 V: v/ x7 ^9 l; mans =% g* ^" y' p+ L! T: B- O8 p$ h" D( L
         1! K1 }: M! e( I  E6 _
    ans =
    1 c+ a! N( g2 h     10 h. R$ {) A5 u
    ans =) o9 @: H7 F$ \4 V# ?2 G
         0
    $ A& |' O( ]0 Px =
    5 A  X6 @4 |- n; d) tHello
    0 u. F# X3 q- h0 H0 f+ tans =, w4 U, d( E! D/ R( q. `
         0
    / \4 ^+ C8 A' U3 g* a: Qans =* _( n; ]# `; X/ @& O
         0
    4 M, O  g- T8 ?/ z$ j- E6 lans =% c$ d+ U$ ^) ^! K9 V
         10 H1 O2 N4 i- R& R- _7 L* [  b# S
    ans =
    8 t# K8 ^8 J+ b4 J! y- H$ [/ B     0: m( b" J7 @+ R% J, D
    ans =
    , q, L6 ^1 R# N) e5 e     0
    / D% A; s  ?" f5 M# V0 r/ |! J6 K: |4 z7 q
    ————————————————
    / u  x! D8 D9 T6 i  g1 E版权声明:本文为CSDN博主「Phil__ming」的原创文章。
    * ~( i1 Y2 C( a+ P原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575
    / k' J7 k( `/ c; ^  x+ L) f
    * J( T/ V( y2 g
    $ q0 j* P, z! }, B3 e
    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-4-19 07:50 , Processed in 0.401917 second(s), 57 queries .

    回顶部