QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3359|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。: T+ Z& M, E- F% b

      b# c8 ^, ]3 e6 G如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。/ j& E$ F9 U( f, {
    ) Q3 d5 f- v! Z6 @" R
    例如,3 l" j& f1 b  f; I7 i$ u
    1 e. F- j3 e3 U) e6 g( y. t
    Total = 42* ]% C' L; t! I( P8 L6 C
    上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。
    % r+ M! a  ?/ [3 D# u( x( c' w7 r- x/ U9 Q( g! ^
    MATLAB中可用的数据类型
    $ k$ m. n9 ~, G6 S$ X0 ~  h1 U' O/ _
    MATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。, y: m+ z- F; w

    : H. u/ C0 i' v0 y$ b3 k下表显示了在 MATLAB 中最常用的数据类型:
    1 }# |0 H) I- P* {; X3 Y
    1 D# ?% Q' M$ i数据类型        描述
    . z8 A" U& {+ b: w/ yint8        8-bit signed integer& ^3 `6 ~+ G- E' p
    uint8        8-bit unsigned integer
    ! H. |) z$ X( S' g8 {( ]  V2 bint16        16-bit signed integer8 A) \% ~2 o* T* n3 Y, H3 p/ d7 _7 k$ f
    uint16        16-bit unsigned integer. Q6 x- c& x) ]$ [9 C, C. _/ g
    int32        32-bit signed integer
    ' @6 K2 @- b4 o; N# guint32        32-bit unsigned integer. O+ w/ r! n) w# G! T' {
    int64        64-bit signed integer  w& U- {4 q+ ]) H+ @6 |
    uint64        64-bit unsigned integer# b" S0 g; k  ^( F* B
    single        single precision numerical data
    3 Z* Z# j- T- m! h" n' W% [% bdouble        double precision numerical data& z$ H/ Q% a7 r; \
    logical        logical values of 1 or 0, represent true and false respectively
    ! ^$ }" ^- Q( \2 ]. o  Echar        character data (strings are stored as vector of characters)  l9 ~2 G. A( R7 ~
    cell array        array of indexed cells, each capable of storing an array of a different dimension and data type
    ' j! a3 ]. E, F$ F7 D# q8 istructure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type
      l8 r8 X7 M& g0 Afunction handle        yiibaier to a function
    2 t/ F' z! y+ muser classes        objects constructed from a user-defined class
    : ~6 T8 j! o8 Njava classes        objects constructed from a Java class! ?$ \8 f; x/ f- U. D. _5 @
    例子5 ~. G: E3 f- }5 a, g
    # H& ?4 M) Y+ c' h- \! X9 m
    创建一个脚本文件,用下面的代码:1 J3 j! p; [1 b& F3 T

    ! j/ a' e& u' v. L8 l str = 'Hello World!'1 d! k8 z8 p  N7 k" \/ V
    n = 23456 y7 X- R/ U7 K: t/ Y  s0 S/ r
    d = double(n); w, C9 Q% p# v1 L) i
    un = uint32(789.50)7 J9 k* A% c  ~$ l; F6 d+ }* [4 J% v
    rn = 5678.92347
    7 t" o' g% j: ?2 Ic = int32(rn)
    # D0 T  w% ~3 I4 {8 G! P* B上面的代码编译和执行时,它会产生以下结果:
    ( y# L9 z8 H" U3 u$ U
    - }. R3 n+ T2 F; ]& ]str =* j3 l( Z& t$ i* e7 m( \
    Hello World!
    ' t. U6 L( |! ]* m& O, Rn =* L0 J; j; |$ [- N) V8 c1 w
       2345- f& l( p! |3 W/ z3 V: Q% Y
    d =  F8 _" @" }) c9 v# e
       2345
    & T5 h8 x# a9 k( c/ m) f7 j. h  Lun =& K( v; N: M8 s! V3 ]9 @# Z( i
       7906 a, z. `# l# D7 L
    rn =+ H( P3 I; g/ r) p
       5.6789e+03* h0 n7 S; s* [/ f. j
    c =
    - C' \3 `2 Q- I5 ?   5679
    # D! |: a! |. E  @; |# q" k数据类型转换8 h& K8 W+ e  |. P+ h

    & w7 q" o0 D7 `, l  I4 {$ ]MATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:
    , R% y: j; o6 Q% e# }3 M2 n2 r2 j7 R3 D
    函数        目的/作用. r, _* k6 i+ g6 P4 d% I3 a
    char        Convert to character array (string), X: u1 B' V2 ^7 k1 O
    int2str        Convert integer data to string" U/ p# K3 N( Y, z- k; T' d
    mat2str        Convert matrix to string3 v' V1 ^# p; u$ [
    num2str        Convert number to string1 _/ K0 x+ E; B" t( R/ L
    str2double        Convert string to double-precision value
    & d. G7 l% L- A0 W! Lstr2num        Convert string to number# K8 L; E8 c0 S1 M' Q
    native2unicode        Convert numeric bytes to Unicode characters
    1 L, A8 A2 x! V+ Tunicode2native        Convert Unicode characters to numeric bytes
    ; W1 G' D) ]: P# }base2dec        Convert base N number string to decimal number( {$ z4 y2 T  |+ b) W/ ~
    bin2dec        Convert binary number string to decimal number
    + Z" m2 p2 I6 i5 `) Y# U9 v5 F  h* {dec2base        Convert decimal to base N number in string
    ' d0 V8 z% k: Xdec2bin        Convert decimal to binary number in string) O0 u; T& P2 `; x
    dec2hex        Convert decimal to hexadecimal number in string; b2 r3 t3 L" P% v, D* v; [# F
    hex2dec        Convert hexadecimal number string to decimal number, \! Q, j" C% n8 `5 r- O
    hex2num        Convert hexadecimal number string to double-precision number
    ( N/ z+ c% y1 b1 N) unum2hex        Convert singles and doubles to IEEE hexadecimal strings
    0 G8 U( s& |  Zcell2mat        Convert cell array to numeric array, z4 p# z% S- ?# M* r
    cell2struct        Convert cell array to structure array. y$ X1 c- Z# E  u1 T8 @; `7 H
    cellstr        Create cell array of strings from character array! N. G4 z" j8 M+ p9 f9 T: b2 ?
    mat2cell        Convert array to cell array with potentially different sized cells8 w2 m, e8 w" `/ Y% Y
    num2cell        Convert array to cell array with consistently sized cells
    . ?8 F9 k, z3 m! s7 b/ ]struct2cell        Convert structure to cell array7 X; H& ]. P0 I) f0 u
    测定的数据类型
    ; S6 }9 a/ ]  ~7 f  _' K: w1 x4 @  R0 E
    9 H* d7 _0 g- }/ ^6 xMATLAB 提供各种函数标识数据类型的变量。, K# h- _4 t: Y& s
    . J1 j/ |/ \% Y0 V" E0 E4 p% u
    下表提供了确定一个变量的数据类型的函数:. l# f& i# n, X& X! z( w' q6 F5 j
    2 c2 ^* e  h6 k& z7 @
    函数        目的/作用
    . [/ N! |" R  U; m8 B% Nis        Detect state* D$ d- H+ f' _+ {
    isa        Determine if input is object of specified class
    9 f! @$ S6 H0 j& a2 o6 {iscell        Determine whether input is cell array- T7 J7 p+ C8 \% ~! J7 [" h# U6 o
    iscellstr        Determine whether input is cell array of strings7 |0 O. j: m8 u& K$ x
    ischar        Determine whether item is character array
    " x" S& p- H6 B% W& [9 `isfield        Determine whether input is structure array field
    . c. U: R! j( C) ^3 L- C. risfloat        Determine if input is floating-yiibai array9 U; F/ d! h  ]- ~$ G3 K; Y- J0 I
    ishghandle        True for Handle Graphics object handles- R: X; ~! ~. ^
    isinteger        Determine if input is integer array
    " G" }3 b. W2 |. Wisjava        Determine if input is Java object6 F  O  N/ n, c! g& Q# H$ ?2 v
    islogical        Determine if input is logical array6 ?1 I, i" Y8 ~% h
    isnumeric        Determine if input is numeric array- O. w0 }) J( r& y4 H2 U
    isobject        Determine if input is MATLAB object
    ) ]8 X" e3 V& ?2 ^; x% T! ~isreal        Check if input is real array
    % v6 n& J1 s) w  w5 ]" x& kisscalar        Determine whether input is scalar
    3 {2 d6 B6 s5 S' Y9 d% Nisstr        Determine whether input is character array0 C1 I: d9 _' s/ |4 w6 _8 U
    isstruct        Determine whether input is structure array% v+ J1 E. d7 U& Y" f
    isvector        Determine whether input is vector& V2 N8 e/ o; ?( G) b
    class        Determine class of object
    ! M" v5 B2 M/ D7 e- q7 `1 nvalidateattributes        Check validity of array
    % i0 m; ?) w! M- f( Q) fwhos        List variables in workspace, with sizes and types
    . G: t6 Z" ^$ R' G) @例子' V; k$ v; t3 c

    & B3 a+ T7 W* \) a6 t5 h: ~9 F+ o创建一个脚本文件,用下面的代码:
    0 g! i# y4 k; J" S# y8 {% Q6 B5 `  j. @; h4 N) Z: d8 h
    x = 3
    + P8 T% F' j7 h0 xisinteger(x)
    8 S1 c+ d* D" risfloat(x)) f+ l# I7 y/ k; T, r2 m) d: C
    isvector(x)$ M" N7 Y! b9 y* I
    isscalar(x)
    % h! f* j- b; c) G0 xisnumeric(x)
    , R/ W) m5 ^$ Y6 v+ J8 M1 |# t
    * q9 D! B9 b# J# E0 h2 k2 bx = 23.54
    6 U* {* P7 w$ J7 Q4 B, i% Wisinteger(x)9 Z& v) L1 r. F$ W. z# q; w1 S
    isfloat(x). E# F* \& X* K% ]! @( u7 {
    isvector(x)1 v5 y* j/ t7 c/ E0 U
    isscalar(x)0 n" }8 o: i6 F: w! D8 C
    isnumeric(x)
    / }0 `# E9 ]8 X3 b0 Z) f* n( M
    / g8 Y7 B# B/ b+ F. [x = [1 2 3]2 P) F  K1 I% P& _' {  U; F
    isinteger(x)
    / Z3 Z0 B" F1 V' u) J) iisfloat(x)
    ( ]8 N" J( _- misvector(x)0 Y/ X, r$ f+ L" F% _
    isscalar(x)* @7 n9 I; i/ }5 y# v

    / S7 e4 Q; z0 z" W& N0 I0 Ex = 'Hello'1 ?/ e! G( [- H$ x
    isinteger(x); a9 S4 E7 ?% U5 H1 K& A
    isfloat(x)5 W, w1 G" i0 j& J5 s4 `
    isvector(x); m4 k( m" e! x9 v# `( N; y
    isscalar(x)
    5 P2 V' S2 S! W; Y/ H0 _6 Aisnumeric(x)
    % f1 Z& j; B. \0 F当运行该文件,它会产生以下结果:
    2 v% M2 q  ~; L# G$ [; a
    $ p6 A! u( |' v5 O( Ix =, F9 N$ U. u6 z
         3
    ( z- b. `1 G# Q2 l: bans =
    3 c* i9 o3 {  a7 E5 s     0
    2 m# _5 S: H/ v2 g# P; J! aans =% t; I: ^" l1 D0 I
         13 I+ Z1 q6 \2 _( c+ Z
    ans =
    . {* a# p0 \2 t, z0 z/ B     1- F+ O% A4 R. \1 Z
    ans =
    9 F+ l  R/ y/ A( {     1, ]! Q/ z# S. }& T' l' i9 k0 |
    ans =  i1 h1 \' x. V* F: N6 g
         1
    / f; t8 V' H  [  {; V$ Y) V. ]x =$ e. a9 E* J; M
       23.5400
    , d. o% y# m) J' C0 H2 c! Sans =  s3 X/ A3 k$ ]; D) e
         0
    & @# t' `/ p  vans =
    ( i( S: N. q9 I3 a7 `     1
    ' r! [( D" X1 {7 b' I) I$ O% W- eans =$ F! g( i/ E# z' I
         1
    ! ], v8 }: b( f- Tans =
    1 S, [$ L. u( I7 w     1: b! {' v' I3 h  Z4 o
    ans =
    6 m% v$ Z9 e; B4 i3 Y" L* F% ]     12 X/ J* B; K% C6 Z
    x =2 e* W1 J6 K+ \
         1     2     3
    + d# r  t7 e! B# U" \/ U) `ans =% i* _; H& m6 U
         0! v1 ~+ k0 t' F/ i! @4 V9 y  p
    ans =  e' Z" Z3 g6 p1 ^$ a
         1$ p4 ^' M, }1 p3 x( N
    ans =
    : A; l1 e- m* ^2 U9 \6 x     1
    7 O' Q7 |- m% V, A9 o/ ?7 `ans =
    / `# k  E( T# S1 k8 A     0. @1 g5 B  `2 B2 j0 j) ]8 f3 z
    x =
    5 t* c- ]: U+ [7 LHello1 v& Z& m1 [" i0 ?% M- e
    ans =
    7 {6 [  T6 C% B5 ?/ K2 y     06 G3 k3 g: b/ R: h/ U! x
    ans =
      p9 f1 Y3 H# d$ ~* R4 [$ C# }  g     07 ?9 V$ I& Y8 o- n# x
    ans =
    & z. u9 k: C% v3 s, W6 K" Z) V     1/ h; D' U5 J3 V
    ans =
    3 G( I# r  x6 D0 M     0& X9 Z6 o: a0 g, d  H3 y
    ans =" f* e$ M( x2 o& n: V* `
         0
    0 T8 a6 P3 D8 G* T7 H2 Q0 I
    5 Y) X9 i" T: X3 D% J2 U  z————————————————
    . W1 B$ h( ]4 F4 }7 {版权声明:本文为CSDN博主「Phil__ming」的原创文章。
    ( m, b  U& z9 \/ u$ S原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575
    " s' i* W" m; ~; E4 ~) x6 r% q
    1 G1 ~4 l" ?# C, K  j2 }2 H1 o6 k2 C9 ]4 a
    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 06:02 , Processed in 0.450098 second(s), 57 queries .

    回顶部