QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3366|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。% }6 B+ i9 q6 C- v+ O7 @

    5 z/ M0 ~! H1 V( w) o如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。: P" W2 V( r0 ?6 d& e5 U3 X' H; {

    # `$ k% X. d3 X+ \1 g7 y例如,! F# p3 c" q- c; ]+ w* \

    ! Q6 Z4 |9 C- `$ X6 \, h! ?Total = 427 M* f. Q8 T( m! g
    上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。0 ^5 @, }% p% d# h/ I

    4 S  ?" {3 R2 D+ VMATLAB中可用的数据类型' Z5 q: b$ y8 F; H
    8 ]& W  k- V* D- n6 }4 A1 r# _4 c
    MATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。2 ?5 |1 V/ l9 b0 r6 y5 j, }

    $ d6 r, k( E7 H5 _6 Y( g下表显示了在 MATLAB 中最常用的数据类型:! _) b: i9 c& Z8 Z

    ! H" _; G* a2 K: O8 N数据类型        描述
    ( W% Q& Y- O2 P( a! mint8        8-bit signed integer
    1 S) m3 t" B  n! b) y2 q/ ruint8        8-bit unsigned integer
    6 ?  c2 g9 C% L" }3 G- H: V, Mint16        16-bit signed integer6 w: j! }% J  i0 u3 _$ D# b4 O% e! g
    uint16        16-bit unsigned integer
    9 V+ E4 J0 E% b2 y9 |; mint32        32-bit signed integer1 x! @" d& K4 _5 h+ M5 |5 P
    uint32        32-bit unsigned integer
    ' r. c" A, m+ P" kint64        64-bit signed integer
    7 @+ m  W9 I7 m5 X, k" m1 W* S( Quint64        64-bit unsigned integer
    * F; |2 m  s5 S; N; B6 ~/ R' ]& {% Hsingle        single precision numerical data
    + j& _, T: e- [" D& y# ldouble        double precision numerical data. W( }) |# \, l* W/ G
    logical        logical values of 1 or 0, represent true and false respectively
    ' C( F7 D9 h, d: K5 U! ]" mchar        character data (strings are stored as vector of characters)
    ) O6 J2 t3 a# H+ B" |cell array        array of indexed cells, each capable of storing an array of a different dimension and data type, |# C! J! P( }
    structure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type
    7 v  V7 w8 \1 Q7 ^function handle        yiibaier to a function
    2 T! I% z8 r  i4 w/ k& guser classes        objects constructed from a user-defined class
    ; j- y$ k- W5 x! i$ b! p: B% rjava classes        objects constructed from a Java class  e7 @; e6 L/ b2 A: t
    例子! b0 B# M# m/ z9 W3 p1 N' w
    . ?- D! E3 a5 `$ r
    创建一个脚本文件,用下面的代码:
    7 F5 E0 u- V* C
    7 _7 l8 k. u; m2 H0 c: V9 d str = 'Hello World!'$ d# C. g0 e7 L) O
    n = 2345
    % F( R/ L  W. {* F" Z# G5 wd = double(n)
    6 U/ F% r3 w5 W" q6 k, kun = uint32(789.50), l; A4 h9 }, p; w7 ~+ A- a9 N
    rn = 5678.92347% g( n+ \# |3 \( k4 p0 u
    c = int32(rn)1 v; z0 T) c1 C1 w$ e% M" f- e6 x: u
    上面的代码编译和执行时,它会产生以下结果:
    9 _& j% Q$ J3 U. _2 O7 C* T$ x& c' q9 p* T7 J
    str =7 {% |' T2 j9 \; a9 M% ^$ t. V# E' x; ^( G
    Hello World!
      g. |1 G. u* i) N; u7 ?% zn =- c- z) Q% v' ]) Z) i8 D
       23455 O7 z5 o2 ~3 r5 L
    d =/ U6 H& T: }) ~- E0 c+ C
       2345! L) O7 A% ^) z6 {+ C
    un =
    : o' v( w4 y, R6 T5 b9 N/ u# D   790
    $ d6 g8 |9 _$ {8 t) ~7 G/ T4 |; |, {rn =, D# W% u8 p/ \
       5.6789e+03" g# Q! z0 T5 G4 N4 E* r
    c =( l; k7 u3 e0 ^
       5679- i8 G4 y- K: g4 T
    数据类型转换& [: d' o) N: N5 Y" x. i6 X4 O- p

      O9 V  v9 G% G: ]; yMATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:+ Q5 s; a" C4 [, {! `

    0 g& }8 F" x- p& r( M$ R函数        目的/作用
    & D2 N6 R/ o2 a: Z7 \- A6 D5 uchar        Convert to character array (string)
    3 ?( y) Y  J+ {8 R/ L) _: }' G+ M( |int2str        Convert integer data to string
    2 s  W$ r) A1 b1 b# Pmat2str        Convert matrix to string
    : S4 `2 z7 V, h% {num2str        Convert number to string/ B' l+ S4 l! u7 a. e
    str2double        Convert string to double-precision value
    & _, k4 e1 x, sstr2num        Convert string to number
    / ]& t2 F4 A/ F; h& h5 {native2unicode        Convert numeric bytes to Unicode characters, B, d# B3 E0 D2 ]% ~; }9 x1 m
    unicode2native        Convert Unicode characters to numeric bytes
    1 A+ _3 j8 T! ?+ g: r. g+ ?! }base2dec        Convert base N number string to decimal number
    7 H% T8 i- u& K5 W. |bin2dec        Convert binary number string to decimal number
    1 \6 }! [$ k1 t! Ydec2base        Convert decimal to base N number in string
    5 _" `9 u" _3 W) H  ^, b  e# X8 Adec2bin        Convert decimal to binary number in string
    * B# y, F) D' f8 q# i$ hdec2hex        Convert decimal to hexadecimal number in string
    1 x. i6 U$ W4 r) J0 b/ l1 c& Qhex2dec        Convert hexadecimal number string to decimal number
    ! o) A4 \" t( O, zhex2num        Convert hexadecimal number string to double-precision number; G& [- r. O' t; u. f9 H& n
    num2hex        Convert singles and doubles to IEEE hexadecimal strings
    4 a3 x4 t, N1 ^' _2 Ncell2mat        Convert cell array to numeric array/ E: |/ T$ o8 p. z6 T8 l9 e$ a+ U
    cell2struct        Convert cell array to structure array& K7 [  m9 C0 {! ^3 Y3 _- x
    cellstr        Create cell array of strings from character array& Q6 x# v8 m, r. d. Z; f0 }% s( Y
    mat2cell        Convert array to cell array with potentially different sized cells
    $ o8 l0 \  A& Enum2cell        Convert array to cell array with consistently sized cells# J( W3 {' ~/ ?
    struct2cell        Convert structure to cell array8 N. m) M% U8 j+ W4 |8 w. m7 ]
    测定的数据类型
    ; F$ S6 L# |- {  Y' q  f% s3 C. k6 q+ H5 k2 ]0 b
    MATLAB 提供各种函数标识数据类型的变量。0 j; M' u7 l! q9 C* f+ L

    3 k5 Q5 y* S, X/ }4 a- [下表提供了确定一个变量的数据类型的函数:
    ( D/ J7 i- n7 i" b! @# i0 u
    / I+ r7 s; Z, U4 L" W3 s# H" f) H函数        目的/作用4 L# I0 F; M$ Z+ y$ r2 R6 N$ j
    is        Detect state9 u1 {, Q" C* l
    isa        Determine if input is object of specified class+ j% [, V1 U$ l5 O
    iscell        Determine whether input is cell array
    ' P# A7 y+ i9 H8 s( s& iiscellstr        Determine whether input is cell array of strings. o# e; ?% ?3 z$ `- d
    ischar        Determine whether item is character array& o1 j+ t" A' i
    isfield        Determine whether input is structure array field% Z' D9 ^2 B+ S, K0 X- Y+ S
    isfloat        Determine if input is floating-yiibai array* u: w* v/ V& Q  k
    ishghandle        True for Handle Graphics object handles) Y5 k/ r4 N1 q7 k
    isinteger        Determine if input is integer array
    $ x7 V+ ^: Z* Xisjava        Determine if input is Java object4 w8 ?8 A* t$ ^4 @+ g
    islogical        Determine if input is logical array- L2 Q3 C" ]  e! m+ w/ }
    isnumeric        Determine if input is numeric array! r8 K# t2 C+ ?1 M# y5 m( v
    isobject        Determine if input is MATLAB object  S( b6 }) Q8 u7 V) p+ Q
    isreal        Check if input is real array+ Y  c9 T  c2 p* b' K' t
    isscalar        Determine whether input is scalar7 t0 w+ e# m) h2 g* g% l  b
    isstr        Determine whether input is character array
    - v+ H4 P0 C; R; {, M* Wisstruct        Determine whether input is structure array0 _  r  O$ ^# a6 f4 O% J$ |
    isvector        Determine whether input is vector
    $ @# d+ g3 _7 o" v* d! K( uclass        Determine class of object# i( N) B* `0 e0 U+ p
    validateattributes        Check validity of array
    1 v6 h; k9 a# ]) _, M& Q0 Pwhos        List variables in workspace, with sizes and types
    $ |9 C( i2 ^7 X! H例子
    1 J7 M4 [1 z  y$ A% m3 p' O8 u7 e2 _; a! d
    创建一个脚本文件,用下面的代码:
    4 t( l' x$ x6 F2 o  S0 \* o& x
    # L* R0 O; g3 ~: Mx = 30 c* `8 P" f1 p3 k, t6 m1 g. p
    isinteger(x)
    7 B$ O* A; W  |! a7 Jisfloat(x)! |' o/ T" [3 A4 F
    isvector(x)+ D6 x( ]2 j. `, X  M
    isscalar(x)
    * l, Z0 a; d4 H# N( o0 X. Kisnumeric(x), J2 P: {: J2 j: C
    8 q+ N/ M# n& p4 E( }
    x = 23.54
    7 w: N7 D: B9 @5 u. d9 @7 {isinteger(x); L' l& n! P, g# A
    isfloat(x)1 z2 ?9 L! i* z3 t; U
    isvector(x)
    * p  C, S6 [0 Oisscalar(x), ?, d0 N9 B( ~  g3 G8 r$ L
    isnumeric(x)
    / l5 f  d& e4 i0 c7 Z) H3 C4 T" c" _1 |- z9 f) Z$ e
    x = [1 2 3]
    : q3 y# b& ]# ?0 D4 ~# Risinteger(x)2 s8 G3 ^: G) `% B2 r5 f  x
    isfloat(x)$ T/ ^. h& M' g' p5 @) F$ r
    isvector(x)
    & ^$ m6 k6 N8 O; O* _isscalar(x)
    ! r3 X( g( K& v2 Y& j- B$ G8 A% _3 x0 Y' S
    x = 'Hello'  k, \) U6 e& F1 D; y1 E, `- N
    isinteger(x)
    6 O- `0 u% r( S7 Yisfloat(x)3 S$ m, G' ]8 Z1 D
    isvector(x)
    ; [% ^1 I" V0 l. y4 B3 Visscalar(x)9 _2 e0 L' B+ N5 }' V6 v' K" h. C
    isnumeric(x)  f9 [' Y* R" s
    当运行该文件,它会产生以下结果:
    * ~1 R9 \  g. X1 P6 b9 K7 h4 d! m" V( r/ C5 d+ H: M  Z, J6 r) k& J
    x =
    " _4 C' |% |, R# R1 W     3
    : i! J8 y; X! X1 Q8 [( i+ r" O+ mans =1 J! R- i$ t* V) j
         0! B: j$ t1 o0 ^6 e
    ans =% v+ c- J6 j2 ~: T+ b
         13 |) T9 P$ U- ^) i7 ]9 `
    ans =
    " s* D! m" P% a* {0 q     1/ T7 ]1 U; M; d2 ]3 _
    ans =! }. K" F& J* t; n) @
         1! [9 D. A5 T& v
    ans =
    + o. `; k. |& e+ y6 x     1$ E  V, ?, L4 k  H! H
    x =
    - E: ^5 ^, h% Z& T9 H7 f   23.5400' r/ p9 x$ L  G& h& |7 Q
    ans =& D1 R" n. L. j
         0
    3 S' ^8 ^, s  `) t& R; hans =! ]6 w- L* ~, M: A+ }$ n7 i2 S
         1
    : L& h( q7 P3 f9 Wans =
    : F* I& _$ d: D8 f" V     1
    + m/ I! |' D- U7 t6 t8 g% Tans =
      Z8 _0 X' d4 m+ `     1+ I6 T, T, N; X7 A8 ^' @
    ans =
    , I6 r( ^9 \& E4 r  A1 c     12 u. o% _" F2 F
    x =" C4 o( K) V" V
         1     2     33 [+ E' ^; e) w1 N# a  m
    ans =% a5 W3 K% m$ r8 q' Z
         0
      {1 O7 r) v- Z' B! g$ D0 O% |) Q9 wans =
    + V0 a: H5 L: O: n$ e% T" B     1! c$ t6 [0 r, Z' @% T
    ans =7 I( Z9 C5 b. |# G4 c0 j! R+ S5 g
         1
    8 ?! C; G$ p' [ans =2 G5 |, p2 x. B  L- }
         0
    1 q  R$ s/ H/ q; T: {/ Mx =
    8 n+ T% l: ?! _/ LHello5 U8 B& p: P$ S$ @2 d) ?5 G3 K
    ans =9 F7 ]+ g- `$ V( S) y
         0
    % n0 F: P  d& }9 C- Z' P: Fans =
    3 j' z) q; W, B% h& s$ O$ |7 V+ ^     0
    / l5 J1 R* c8 U" F: Pans =0 J3 N/ p1 G0 x' [9 o+ n
         1  }* z4 y& z8 d
    ans =1 V8 l* ~6 c# e$ Q1 ^. Z
         08 @. W) K% l0 M1 x7 w# c
    ans =
    $ |$ w- d9 u+ [     0/ X( I- f" |6 [' V5 x

      \7 O5 t% I+ S5 l. P1 K( w* {' ]1 l————————————————( x& ?: A% S, B4 s
    版权声明:本文为CSDN博主「Phil__ming」的原创文章。
    7 J  Q# h4 H1 T/ w. ~原文链接:https://blog.csdn.net/Poseidon__ming/article/details/750925755 {6 s  v) G. E" Z1 \
    : B& K. U7 p: E$ [

    1 |9 |1 y: y( u" k; P
    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-20 21:09 , Processed in 0.427615 second(s), 56 queries .

    回顶部