QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3375|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。
    + {* o5 n3 ]  _( s/ ?. a! {. |8 [' r1 n% |2 }/ i
    如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。# Q3 D. x7 W  C* w, J
    1 K, Z0 Z  N/ }3 f  v
    例如,
    7 J' x  V$ C4 X* Q  F+ A. j& l# S7 i# m8 _' E. n( K
    Total = 42
    - R3 I' T* C! ^- D& g- E上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。
    8 A" f+ j' @3 V& I0 q
    ; {9 e1 {4 N% o. m" z( sMATLAB中可用的数据类型( X9 I$ d; i3 f( E3 Y, P1 H7 l

    2 F5 Z) \! k) m- i5 O% j  v0 vMATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。% r/ v, @- z0 o6 e* [; E
    3 R& T1 @7 x, O6 @# d
    下表显示了在 MATLAB 中最常用的数据类型:
    7 n- k* @& {4 E( y, ~3 [+ b2 a& R& T% j# K" x) w4 L1 e# s! o
    数据类型        描述9 P# C. }. L: i3 N! I  w% s0 @
    int8        8-bit signed integer. I, [" M  k* x; r
    uint8        8-bit unsigned integer5 h4 F8 N( F' j. Q+ o4 A
    int16        16-bit signed integer' G+ R: [) W2 N" W$ [5 i1 d
    uint16        16-bit unsigned integer
    - D7 @$ Y+ b3 ~% Q8 w, m( Mint32        32-bit signed integer6 `" r7 X; Z, \! e0 L
    uint32        32-bit unsigned integer( _( ~5 s3 G# P
    int64        64-bit signed integer8 I, e! \6 H0 i3 s6 j. U
    uint64        64-bit unsigned integer- t9 H! c* x3 a  U9 j3 ?' W
    single        single precision numerical data3 S' ~. s4 R1 m, ?* x) d6 ^
    double        double precision numerical data: E3 I: B. E& e/ L2 G7 J. }0 |- H
    logical        logical values of 1 or 0, represent true and false respectively
    * g: g. t$ w3 a/ Pchar        character data (strings are stored as vector of characters)
      \* v% c0 P7 W! E; A7 Z  Ocell array        array of indexed cells, each capable of storing an array of a different dimension and data type! ^, k4 a: v1 b. H: A
    structure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type
    + w5 l: ]( G' M; R5 p4 [  {0 E; qfunction handle        yiibaier to a function
    + N- ]/ b, e2 \7 `$ vuser classes        objects constructed from a user-defined class* E7 w2 [: q9 a1 a2 E: A. O, f0 l
    java classes        objects constructed from a Java class+ O# T; }3 N  U. D7 Y- U
    例子
    . E+ v% K$ |7 Y: _) j! h8 t6 H
      U$ \& ]: h4 Q; t2 Y  p. @. @创建一个脚本文件,用下面的代码:
    . u0 [- X2 R. I# r
    " f/ i% u$ a  f5 K, i5 k. _. K  I str = 'Hello World!'
    , Y2 e8 r8 ]+ J; g- d8 d+ ?n = 23455 I& ^9 s$ U# L7 o* S/ E" M! l
    d = double(n)& _( }) V7 ^; v5 A& Q  Y
    un = uint32(789.50)
    3 w1 T2 d) M( O0 ^- X) grn = 5678.92347
    . ]) b$ p+ J8 G7 v5 Y3 A! Jc = int32(rn)
    9 F- _5 ^6 v2 R上面的代码编译和执行时,它会产生以下结果:
    & S0 K( m" u& T, b9 L% U6 N* ]# c4 T/ c# z' y) f
    str =
      a5 w$ n2 O9 h, f* MHello World!( y+ v) [1 d% N+ S1 F9 o
    n =8 o2 h1 s! K  e# r* Q
       2345
    + |" l- ^% y. N' |+ @, U" f  cd =3 }% n. N! `2 i# [8 m$ v7 C
       2345$ d5 o$ c; ?: F
    un =
    3 }; |8 ~! n' c   790
    ; y: q  g1 }; J2 q3 P/ C5 f' Drn =; m9 w9 v% A0 {( j3 D
       5.6789e+03
    * |$ X! [* H: Uc =
    1 B! g# Z" v- Y: \7 p& A0 R   5679
    + n2 |6 r, `) f' C4 q数据类型转换! D3 F7 Z+ O0 w' d1 r! |
    ( f3 O/ h# M$ i# K
    MATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:: W# }+ b* _9 W: {$ N" Z
    5 p6 I$ _+ \# G- O7 T  c, N
    函数        目的/作用& N  @. X% B( L/ f
    char        Convert to character array (string)
      b7 z/ v2 Q0 u5 Mint2str        Convert integer data to string9 S* Y2 B+ X! _) _) P
    mat2str        Convert matrix to string5 H* U- Y1 q9 t5 z: Q
    num2str        Convert number to string
    ) L: Y* Z% m; w& \% |str2double        Convert string to double-precision value- x% m  \5 `+ N# Y6 B4 X
    str2num        Convert string to number
    * Z0 B7 S+ D, U' J. }2 C% E9 `, S6 P* dnative2unicode        Convert numeric bytes to Unicode characters
    - X8 Z' i4 _( Lunicode2native        Convert Unicode characters to numeric bytes) N9 j  X5 ]& `/ v3 d3 K8 f, L. c6 X
    base2dec        Convert base N number string to decimal number
    , e" J) m+ S" \7 obin2dec        Convert binary number string to decimal number9 i5 ~! g* j7 P  G# L9 T, r
    dec2base        Convert decimal to base N number in string" o5 b* X# w( k7 j( A' S8 V& p7 S4 L
    dec2bin        Convert decimal to binary number in string! {9 H: ]* @* \+ ^9 R& h
    dec2hex        Convert decimal to hexadecimal number in string
    7 m/ f- }: j7 y# b% E. Ohex2dec        Convert hexadecimal number string to decimal number5 n7 m& b3 _7 E# O
    hex2num        Convert hexadecimal number string to double-precision number7 t. @2 C) ]4 |3 j) z: V& z6 }
    num2hex        Convert singles and doubles to IEEE hexadecimal strings8 s9 Z# q/ F! t: o" i7 H3 f
    cell2mat        Convert cell array to numeric array
    1 i* ~" t/ \5 R; c7 [cell2struct        Convert cell array to structure array
    7 V% [8 z- ~2 b4 @; y8 Ucellstr        Create cell array of strings from character array
    * ^( b/ _, w. n) Y/ Pmat2cell        Convert array to cell array with potentially different sized cells
    : V4 i# d) w1 y, rnum2cell        Convert array to cell array with consistently sized cells
    + s+ {* D# ~' }/ M: A! Xstruct2cell        Convert structure to cell array9 ^$ U1 I8 r% |; q
    测定的数据类型
    7 g' \2 t% c* V3 R, L7 j& F. q0 [) ]# K  y/ F
    MATLAB 提供各种函数标识数据类型的变量。, }: t2 g6 b- C6 z$ G: D
    9 R: X, q/ [- `
    下表提供了确定一个变量的数据类型的函数:
    * M) `( j3 k7 A( U9 c1 r: r" F0 ]- M0 @* c/ U
    函数        目的/作用
    4 I/ o; x3 @" e1 n- M+ Zis        Detect state
      S2 r  P# y' B7 R- C9 b6 bisa        Determine if input is object of specified class& ?% @3 a5 [* t1 n8 s( V# x8 z" M+ Q
    iscell        Determine whether input is cell array
    # a- J* ?) _5 k- Z: I6 h# D" qiscellstr        Determine whether input is cell array of strings
    8 v) W8 u6 K# [  l2 tischar        Determine whether item is character array
    # k# P- K# m6 disfield        Determine whether input is structure array field& W, x& M) z6 G
    isfloat        Determine if input is floating-yiibai array( @7 q* g  x3 P3 l- B
    ishghandle        True for Handle Graphics object handles
    7 [6 \4 Y  j" I, I# W# {7 d0 xisinteger        Determine if input is integer array
    7 i, o& p6 J/ r# ^8 i9 `- {isjava        Determine if input is Java object- o4 a- f* Y" P: ~6 u9 m
    islogical        Determine if input is logical array
    * f% o) C' Y8 R0 P* N& d$ F. yisnumeric        Determine if input is numeric array
    5 g2 b8 J/ _# i& Wisobject        Determine if input is MATLAB object. U% P! `# _* L8 E% }
    isreal        Check if input is real array9 O9 d3 X5 l1 ^
    isscalar        Determine whether input is scalar5 q" B8 L2 J- X7 b0 U+ N
    isstr        Determine whether input is character array+ t5 z* V! z( Z+ `- h, j" b  ]
    isstruct        Determine whether input is structure array
      d1 T( a5 j- |- o3 wisvector        Determine whether input is vector
    : _0 i1 o. S7 F7 m- Lclass        Determine class of object
    6 U1 H4 h: T  f6 J: Xvalidateattributes        Check validity of array
    # @. N5 T1 b1 K5 J1 e  c7 J: C" Jwhos        List variables in workspace, with sizes and types2 n  F/ [$ D: M6 l8 M
    例子, |' h8 p8 M, U# m/ Z$ d, s7 F
    ; J3 P/ V' Q. p9 J6 Q
    创建一个脚本文件,用下面的代码:4 ~* j# ^. M/ G

    ; T( i# V1 w- H0 {, Bx = 3
    8 |2 t  J$ P. U$ W/ ?isinteger(x)# B# x7 q/ q! V* k# |( E8 {1 l
    isfloat(x)9 Q$ ?" H4 z' W2 W# k
    isvector(x)
    8 W7 A8 J' Y% [isscalar(x)6 Q  i% D) m; r$ o$ C1 h
    isnumeric(x)+ t% q8 W' e. F  m& g

    6 a* p7 w" S3 ]x = 23.54
    3 ^" A2 R6 s4 S" U' nisinteger(x)
    / [# n5 K, f1 \isfloat(x)
    8 \2 V- N& m3 Jisvector(x)
    ' h0 ]% J# w2 B: Q+ i7 w% Z; s* e; X1 Bisscalar(x)
    ) U" W+ g+ M, z* j4 T2 ]isnumeric(x)7 C/ s) D' u. ]6 n5 s- B

    2 Z+ a2 G  ^  x6 o6 Cx = [1 2 3]
    0 G) V, x9 v) ]  O0 z9 ]7 w% u. Oisinteger(x)
    8 n0 g3 J9 O! S' f2 K+ visfloat(x)( @" ~3 Z$ Q& i8 y
    isvector(x)
    / M% U# ~3 e4 S. U( b3 k' Fisscalar(x)
    * ^7 s0 O: j, m* E9 e" j/ n  p2 b0 `$ {& A/ w
    x = 'Hello'6 q8 s' [$ U2 N7 I* [  _' t
    isinteger(x)0 [% Q- u/ |4 y  O+ R  w' i7 v5 v
    isfloat(x)
    9 u3 U3 x4 d9 xisvector(x)4 v* x% E5 W$ w; H
    isscalar(x)" H- c2 G$ o' d) Y5 o. t; B) R
    isnumeric(x)
    ! r0 P& B2 O' `1 K- Y$ ~" }  N/ V7 R( M当运行该文件,它会产生以下结果:& m$ }8 a" x2 ?, F* R# F! ]/ {

      ~/ r' c/ a, {' [x =+ _1 [- E1 p! J" _7 D
         3
      {  ~0 b5 h6 K$ e3 kans =- v' k0 v1 N) ~/ ?( O+ R0 F6 e
         00 n+ H: N# p7 S. R* s# ?2 k. h# y. D
    ans =, a9 k" Q5 Z+ F- Y4 n; j
         1
    0 R: J$ N* l* [( pans =$ q+ P: e! s3 \, F& ]
         1; i1 d  u; W4 M5 B6 {
    ans =! X" x8 u. W7 e$ D% x
         1  [5 X  d  B' J' H2 Z5 Q
    ans =3 i. \4 j; v* C' D$ S% z
         1
    ; O4 B/ _/ d+ E" wx =
    " h+ {) g8 |8 N* Y0 V% E   23.5400
    3 L' o* z6 {* b' Q$ cans =2 |3 e5 X# O2 \) m& W6 Z+ @
         0
    # L) X; W' t4 _+ s0 n! rans =! c) D2 C& I$ m: L! J
         1& s* W+ a' A; K7 d, M
    ans =+ ^1 c1 g" _7 l1 `8 `* W; x
         1
    * }1 T6 G$ u; b1 e+ T/ ~& R6 mans =
    $ @+ S" x! ^) s/ ?     1
    9 a; w; G& z( r- I7 ^9 W# mans =
    9 |# M2 i0 ~8 \" @& W, j* x     1
    ! m% K1 ~6 e7 bx =
      X  |& O0 z5 U; f2 H; P% g3 z2 E     1     2     3
    + m7 P+ ~4 Q9 J4 f0 Ians =
    . L& X3 f; ]- Q, r! b6 B  M     06 V" ^4 f/ N) F" g: Z' {% z* y$ [5 g6 y) _
    ans =
    4 e/ q4 F3 ~" h' U7 P     1+ l, X" f7 x5 r) v" f3 w( E8 B/ w
    ans =
    6 J  L& {5 y- S5 U7 n" t     1
    ; @7 T4 M( s  M. R# R+ Pans =
    ( L5 f. Y4 r( |: a/ M     0' g4 G, _1 _. O' Z0 ~& [
    x =7 A  G+ d. q) f9 R& d1 F1 P
    Hello; A/ v+ C& R4 D0 `% `
    ans =
    % g3 ~, i& v& U     0
    - E. A7 F% O: y; \! Uans =/ G, ~% a% Z; H7 Z$ _
         0" [% ?: m8 A5 e& [. c
    ans =- K' M6 \/ G# F  t6 w# N
         1
    * m! U2 V& u" I7 wans =
    ; @5 q3 _8 r; G5 O4 A     0
    # Y4 g6 j# `& [4 Z2 G9 ?; C: m5 N  Fans =
    # h$ q: ^$ i6 n) g8 |     01 _4 _$ }# e, P1 z" n

    0 g" k% w( s+ H. y# b% B5 ~& Q8 A% Q————————————————
    3 ~2 G* X. m0 a版权声明:本文为CSDN博主「Phil__ming」的原创文章。
    ! K: _7 K+ r1 e7 r. J( @原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575
    ( b. b( M6 m( ^1 u! y
    / m8 v7 X( R/ Z
    * Q+ C1 S! e8 D3 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-5-3 20:08 , Processed in 0.867964 second(s), 57 queries .

    回顶部