QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3419|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。' s( r9 A) M9 L0 e$ G

    6 b  A) R: Q  r$ @( M7 n如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。
    # n& \' K$ g, L, t7 K9 H0 R" p# g4 M7 S' V" b. u7 w  q, n
    例如,% m2 f; R% M% M* D" E* [( \

    3 S1 X. I. M/ {/ ATotal = 42
    ; M" u) i. e' W# h, `; k/ j% A! p上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。
    / }" ]1 R$ ], w* T" ~) a' O( A2 x; v7 ?% e2 P7 c0 |4 O/ _4 s
    MATLAB中可用的数据类型
      k9 n  x1 U) l7 K6 _/ U  A/ p, U+ R
    MATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。
    7 w! e  ?1 Y0 q, _, N2 ~1 c/ n9 K- X8 V( k8 V" a' s, G# ?/ J# b
    下表显示了在 MATLAB 中最常用的数据类型:
    . G/ B- s! K" D2 c1 Z# L! F7 k9 F6 w  }: b- N+ \
    数据类型        描述4 s( P: V+ }) j& [1 U! H7 T
    int8        8-bit signed integer4 U6 ]. w- C6 i; f! U) w2 }0 m
    uint8        8-bit unsigned integer8 ?* D/ _7 U- x, m  \( F# }. S
    int16        16-bit signed integer
    5 [% Z. }" Z* K7 @1 E+ ^uint16        16-bit unsigned integer
    ; w9 P) @8 J1 c, E6 Z$ r* m, Zint32        32-bit signed integer! Z: w# t$ v! W) E5 h: L% X
    uint32        32-bit unsigned integer& n: y) s/ N3 \5 Y" u% X
    int64        64-bit signed integer% a% k+ C: L3 Z; A2 l" d
    uint64        64-bit unsigned integer  }6 z; |* y7 ~
    single        single precision numerical data% V! Z* m9 S) T8 G" `% `% n/ o
    double        double precision numerical data6 h" g0 b6 L: ?: G: N
    logical        logical values of 1 or 0, represent true and false respectively# _2 b  x2 \+ L$ Q* r! k4 D3 }
    char        character data (strings are stored as vector of characters)0 @9 Q2 }! }0 [, @( t+ D7 e
    cell array        array of indexed cells, each capable of storing an array of a different dimension and data type
    $ L! o3 E6 M) [1 Y8 Estructure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type# x1 L  w$ A3 A
    function handle        yiibaier to a function
    : m, t  |! c! L4 h5 Zuser classes        objects constructed from a user-defined class
    / R! Y& }' A' p. E1 bjava classes        objects constructed from a Java class
    + S6 [# K$ t6 K0 Z. L8 |# a  n例子
    ) I1 D+ K5 G" ^1 k! U3 s3 C# K9 Y. u/ Y6 R! M: b$ j. i' F6 t
    创建一个脚本文件,用下面的代码:
    - ]  P- L8 D; `3 G2 f7 z3 D% e: G! O$ p7 Z/ p) Z. E- r
    str = 'Hello World!'
    - W. a4 V8 X0 P) x: rn = 2345
    1 S/ d/ c; _2 h/ W  b: xd = double(n)
    5 B1 C2 ~' ^7 Tun = uint32(789.50)
    * w% _0 M4 `5 Z3 brn = 5678.92347
    4 g- N8 [/ e# y" y- a# y* H0 Bc = int32(rn)" [( N7 z& h: z( u; v# b. K
    上面的代码编译和执行时,它会产生以下结果:
    * O) t4 Q5 p5 _' ^( @+ ]# F
    8 w: V' m! u4 F$ kstr =2 W% j7 h8 u  i$ B
    Hello World!9 }5 V8 ?/ U' f8 f$ @# T
    n =
    . ~  J8 I; ?- s; N$ v  I$ b   23456 i* R, C3 H, z3 [) ]
    d =* z" q  y) t) e% I0 k7 Z( M) a
       2345: Q. U( A. K* c, @6 ^
    un =
    7 r+ k% D- [$ s   790' k$ ^* h% J, v3 e: M$ Z* Z" C5 m3 E
    rn =% B& q8 o, H0 S0 N' r1 I  W
       5.6789e+03
    2 b2 {; K  n# N( ic =
    $ }( `3 i, e6 m- H   5679
    - D: r: s% C" f0 @数据类型转换) b! b5 M9 I' F: ~7 d$ o2 o

    9 X( C+ G( J2 J9 D0 SMATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:
    + f! ~# X: z) T6 _0 X& `; ~0 c! E) n) D' P* U1 V. h9 U
    函数        目的/作用5 w! C: y  j  i
    char        Convert to character array (string)$ G! r. a/ J; d' g4 I
    int2str        Convert integer data to string
    + x' q  c- U# k8 f8 {mat2str        Convert matrix to string  O6 u# P! W% k4 B
    num2str        Convert number to string9 Y" R, H' X( t4 J) A. O! k
    str2double        Convert string to double-precision value
    2 u' @! N1 b4 T& Zstr2num        Convert string to number* b1 a  }/ o7 u, g" U; o
    native2unicode        Convert numeric bytes to Unicode characters
    : l6 z% [' k* `unicode2native        Convert Unicode characters to numeric bytes
    - O1 u/ g4 n9 u! j4 tbase2dec        Convert base N number string to decimal number
    1 x+ V8 x7 d0 I' T% Ybin2dec        Convert binary number string to decimal number! R% h% ~. e9 l1 X6 f5 r
    dec2base        Convert decimal to base N number in string3 T, t9 H# V- K/ ~1 s
    dec2bin        Convert decimal to binary number in string
    ) F# S5 ]6 @# e0 Zdec2hex        Convert decimal to hexadecimal number in string* t, R: ~0 }5 a
    hex2dec        Convert hexadecimal number string to decimal number1 E# x$ C& Y! L* Y% z5 K
    hex2num        Convert hexadecimal number string to double-precision number. h' a; C) F* ?1 X3 s- D
    num2hex        Convert singles and doubles to IEEE hexadecimal strings
    * }. }, {1 r+ A7 [+ |: ^, Ncell2mat        Convert cell array to numeric array* f1 b0 I! r4 M
    cell2struct        Convert cell array to structure array
    0 T) X5 H7 `9 n! X9 D2 mcellstr        Create cell array of strings from character array: ?$ p+ K. u2 m& S! f+ I) ?
    mat2cell        Convert array to cell array with potentially different sized cells
    0 \+ h( u- m: E$ X& N! d$ H5 @num2cell        Convert array to cell array with consistently sized cells
    $ g- g4 M0 M, n5 A  |& ]struct2cell        Convert structure to cell array/ }% n) S( E3 j0 D% W  l$ p! f0 O
    测定的数据类型
    7 R. q9 z: Z3 M, {- p% c- H% V$ p: x  _/ s; g$ P/ _
    MATLAB 提供各种函数标识数据类型的变量。# S7 ?/ c' ?$ T' N4 f: r
    + S# r- ]/ h3 p9 a2 c" T' [
    下表提供了确定一个变量的数据类型的函数:- [' y3 \8 G- r3 G7 r8 L) u

    5 |8 p* ~! R* w% K* \# _8 x8 ^% d, h/ Z函数        目的/作用" v. I7 K* p; h( r
    is        Detect state
    6 C  \1 i' ]. e2 S# q- z2 oisa        Determine if input is object of specified class
    7 `6 {) Q( G6 Uiscell        Determine whether input is cell array
    , U' \+ C/ U  D# Wiscellstr        Determine whether input is cell array of strings
    6 b: B6 B; \3 z; K3 G8 Lischar        Determine whether item is character array
    ' G' J: m! D  I3 r  Pisfield        Determine whether input is structure array field, W$ o& U& ]- i
    isfloat        Determine if input is floating-yiibai array8 I. F! y7 q" J8 _& N2 W
    ishghandle        True for Handle Graphics object handles1 \% \: b! p" ]! ~, l) u
    isinteger        Determine if input is integer array
    1 O3 ^( s; ?$ J) Y) J1 s" L' u4 o: L, eisjava        Determine if input is Java object5 c7 a' p2 j; `% A. e
    islogical        Determine if input is logical array$ s' i& I; n* N3 A  ^% K
    isnumeric        Determine if input is numeric array5 z1 n( M; B8 {# V- e# u0 o9 N4 a6 L
    isobject        Determine if input is MATLAB object
    . `* }& U2 }( C+ Y% eisreal        Check if input is real array
    ; w% y  }' q8 b8 i! ]0 C6 Eisscalar        Determine whether input is scalar
    ! x1 H" p) q! Y4 e) @/ a: nisstr        Determine whether input is character array* n1 J' P- d% j% z
    isstruct        Determine whether input is structure array
    7 t* ~* Z+ R+ X' {' `9 xisvector        Determine whether input is vector
    6 F3 l$ u8 T3 bclass        Determine class of object
    , S# p2 y, Z) w# c& n* b# r+ kvalidateattributes        Check validity of array' [* w: i: C4 y+ b; v! M9 {
    whos        List variables in workspace, with sizes and types
    9 k2 J) k+ j5 x例子+ S; k0 L- ~3 h/ C
    ( Y; d, ^6 b4 s6 o/ T( f. [
    创建一个脚本文件,用下面的代码:
    * ?0 m+ P2 r! V+ o% M: Y: ?: c7 ^( g8 W3 M7 @; Z
    x = 3
    5 Y' I& W+ B. ?, \7 Iisinteger(x); {$ I4 e9 F& ~; s
    isfloat(x)
    . }1 X, h. t3 n9 j/ X0 t; j! v5 gisvector(x)
    & t1 M. |+ {/ M: ]$ v8 ?isscalar(x)& r6 R( \' [, j8 r1 u
    isnumeric(x)" v; t6 X( v4 H9 J
    6 ^9 {# {) I) |7 H
    x = 23.548 v+ b/ z& O# O8 k( h
    isinteger(x)
    ; S3 \, W- N  g# V  y! D! o' Fisfloat(x), C5 N0 @9 d. ]. M) S. P, P- e
    isvector(x)" R5 z% o9 n+ B8 @: {8 o; f
    isscalar(x)
    6 M7 y/ i! a4 p. {  y4 ^isnumeric(x)
    ( U) z( M% K: J5 P% f
    6 P0 K  v" d# N% S! ~) s# a/ Ux = [1 2 3]3 r6 d2 k9 A5 _; y7 _6 e/ }
    isinteger(x)
    " i" Q1 Q6 S5 F2 {isfloat(x)
    0 _/ x( a: h: K# X  Hisvector(x)
    1 C9 C% V* E- s5 T" h0 Z* \3 ?isscalar(x)
    ) Y, W/ d: t4 k
    3 b- I3 o  _) }, K+ `* P$ Px = 'Hello'
    - W  K/ G, e  Zisinteger(x)
    3 e+ c0 k. `* m0 u' ]isfloat(x)) Y" t3 C3 [! l: X7 Y) d: N1 J* Y
    isvector(x)# A8 A, b4 ]8 z- P& j, J" z7 u
    isscalar(x)
    + c  p' T# ~* d9 Z2 z& F8 W# sisnumeric(x)% R: X4 H. o) G) ^8 I
    当运行该文件,它会产生以下结果:& U9 @! \5 m# \# P1 S, V2 H
    & [0 r! G# J9 B
    x =
    , o: ?) ^" A3 p! `: b( p! Q     3
    & c& k( r$ k+ F1 j; M% Cans =
    4 P7 Z5 d; D' m: W- G4 ^     0) R  F& r  _9 [6 u; }
    ans =3 ^$ X3 c+ e; {2 a/ a
         1$ S9 A/ P$ \8 K6 `- N3 m( v
    ans =
    & m/ x! g/ T4 H; z  ~( x     1
    ! q/ L+ _0 F! @( Yans =7 B8 ]2 a$ Q9 D, p
         1  f/ c" G8 Y$ o* c
    ans =: c: m- }: f5 f( B# N9 p+ e5 W  _$ _, y
         15 I: Q5 n; J# Z$ w% q
    x =
    , [+ f  ~! Y  o! V   23.54009 y) R& w, _5 z& l; x9 I2 k* a/ [
    ans =
    ' U) r% e( e6 j( w; A3 h     0+ l7 ^. n7 T' o& ~9 U- ~* m
    ans =0 D% g! z1 s( L7 \
         14 I3 t& L. o7 Q/ f
    ans =
    5 E$ {7 d! M0 _1 {. N  @5 {5 K     1+ d2 \4 l& _4 s' g) @: b. S
    ans =1 B; j9 W$ z3 a, R1 _+ G
         18 j/ n& R2 d) G0 s
    ans =0 w  B- R" W; d  v
         1
    , G* z8 Q# F6 s0 z" @/ _! f. Hx =% w  Z9 @8 r% d7 X" s3 O8 w
         1     2     3# ?8 s9 o1 h, c/ J+ J
    ans =
    # _( t& P3 y8 U4 i     0
    " \# ]; \- f4 Y# J5 b, s* Nans =
    . i3 l6 |/ b6 I, C( I; g     19 T1 a* e& e, `6 J( k
    ans =
    4 T/ p3 [  {  S     1
    - P0 b2 M2 a' S& p5 |ans =
    7 j. [8 \  x* v! D6 f/ i( J7 v     0
    ; ^. D  K1 U9 i7 \% z# X% x& |+ Nx =# [- n) w6 z' i( C+ ]
    Hello
    6 [# H$ |4 c0 zans =
    ) N& S+ ^4 r5 k, s     0
    6 W' e# K! u2 A  l3 x4 u1 ~ans =
    * Z/ x& E( [! A1 g, ]     04 O2 Q8 B1 h5 Z) g/ z  g. e  _- \
    ans =
    # F" N% B9 j6 z5 t; }8 W     1
    0 g; _1 o1 z2 E0 W6 }  jans =
    , D# y% z0 J2 \# A& b6 Y     0; M% w( l% L- I6 Y3 x! I
    ans =
    4 i: F8 \0 h. o/ L     0
    + d, |: B# _( r9 G1 V, h- c3 r0 l. J: }8 b
    ————————————————
    2 S, B, V) A9 @( t. C6 w, F版权声明:本文为CSDN博主「Phil__ming」的原创文章。+ N9 t& y1 K! }" }, y& Z
    原文链接:https://blog.csdn.net/Poseidon__ming/article/details/750925751 l4 I3 o9 L2 c0 ^; |

    ; w  K$ [* p  W, a0 D" e% L6 @( K7 _3 K4 n# f% o
    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:01 , Processed in 0.519859 second(s), 57 queries .

    回顶部