QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3131|回复: 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. m0 i% ^$ L
    * S( w2 y# J: V" G如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。! }! \# Q7 c7 k# l- t
    " B4 Y. ?& @+ m
    例如,$ f: R8 R2 |: [+ t( [
    ( [6 f( {. b' y3 @! Y8 J' W
    Total = 425 J; h  o9 H) y( |5 k* z5 Q& |' ^
    上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。
    ) E$ x6 [6 B$ \8 w9 I' c1 P! y' V6 m, K' Z0 B/ K
    MATLAB中可用的数据类型
    % S, G7 w( w% z; V5 @  M% g. Z5 d9 I3 u+ N
    MATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。
    7 \8 L" i/ a1 V( E  u5 V
    # }8 Y; V$ ^+ y1 H! i! M9 V; ~4 ^下表显示了在 MATLAB 中最常用的数据类型:4 T4 ^! K2 N. @' R- K
    1 Y8 U+ [- A( @6 d
    数据类型        描述
    6 h0 u8 x# z0 j! Kint8        8-bit signed integer
    0 G9 d2 F, l/ J& [/ l) uuint8        8-bit unsigned integer! @  J0 D( f) {5 o9 e- ~4 K8 c  h
    int16        16-bit signed integer; A) y5 g9 {6 `) t6 \1 c% E
    uint16        16-bit unsigned integer
    ( @1 w# T/ {' M# Z; dint32        32-bit signed integer
    5 ~- f* w2 q: Y0 Yuint32        32-bit unsigned integer
    5 ~% Y4 f/ i; N4 M) p6 j, R' r+ oint64        64-bit signed integer7 m( H2 L9 h) e' i
    uint64        64-bit unsigned integer
    " F+ N) z$ s' Z1 p& K* |% {single        single precision numerical data
    ! }/ D9 \& Q2 a2 K1 |3 F- tdouble        double precision numerical data' V9 R# C8 C9 l- ^! _7 o
    logical        logical values of 1 or 0, represent true and false respectively. u- M) I" o; s- a1 O4 \+ Q" Q
    char        character data (strings are stored as vector of characters)" A5 _3 g& S/ V. o4 t
    cell array        array of indexed cells, each capable of storing an array of a different dimension and data type# G0 l, |1 d& ]6 v& A+ i; C' n% M' L
    structure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type: E8 q) w! b1 @7 q, G! L
    function handle        yiibaier to a function
    0 A2 @) ?& Z+ U8 _' \user classes        objects constructed from a user-defined class6 d$ d  p5 j# o6 Y
    java classes        objects constructed from a Java class
    9 Z3 G$ `8 e& F3 w" v例子
    ) m) |7 {$ \* M/ v6 C% g6 f" u+ z0 p- m/ ?
    创建一个脚本文件,用下面的代码:) w- v. i( v* v3 U" Z
    7 N5 r8 }' O5 l: }5 W
    str = 'Hello World!'- s+ M* i) p4 `
    n = 2345
    / z. h' M7 l, H: Xd = double(n)6 n/ U9 J  f. l4 ]+ ]
    un = uint32(789.50)
    2 [# F% I/ v0 b( i- q' C/ Lrn = 5678.92347) a; p6 _% y% j; P( o6 }
    c = int32(rn)( F( h5 r* I  r$ G; j
    上面的代码编译和执行时,它会产生以下结果:
    . T  v: i" m& p" M, X7 f+ S9 p
    $ c  O# Z" N) @, G& sstr =  P7 r9 x8 u, ]! i+ A7 K6 w) v
    Hello World!% S4 e7 t& Z3 d6 i, {
    n =
    1 G  L5 q1 l" W' @   23453 s. f" }+ @% w
    d =' d$ f8 k6 T! ~. {/ @
       23455 t# B. H0 v. a& l: {0 V& m
    un =" f! C4 F9 w- v9 O, D+ t0 V3 m& I
       790  h9 n6 D, ]0 }/ ]% a  }* |2 ^
    rn =
    ( V8 h2 I( f; i+ P1 m   5.6789e+03
    # {! J+ N9 H8 [) j3 `c =
    + R8 v# f3 T. t! p  N  R% D' }8 s   5679
    , E! r7 F& |  z% z; M3 @) D' ]数据类型转换
      \4 D. f8 @0 ~$ s* }5 H* b' J1 J5 \. p& k, ]' @. S
    MATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:- z5 V& a+ y; C! C7 W
    % ^: a1 \3 {$ k4 g7 A8 u7 `
    函数        目的/作用9 E+ g6 @$ ^! m; J
    char        Convert to character array (string)
    + U7 |( p) a, J# J! y: rint2str        Convert integer data to string
    4 ~# s1 M! C  i, y0 qmat2str        Convert matrix to string; R# `: s/ r* G8 O5 U* Z% l0 o
    num2str        Convert number to string  I% g0 e9 S3 O' z" s6 g
    str2double        Convert string to double-precision value1 F) p5 t) I/ B% w3 V
    str2num        Convert string to number) }: N& Y, R* l* i# [" A
    native2unicode        Convert numeric bytes to Unicode characters
    6 V) P6 r: x9 A; k+ Zunicode2native        Convert Unicode characters to numeric bytes
    : z6 g  n1 g! D8 f2 h2 Fbase2dec        Convert base N number string to decimal number
    3 {7 S+ C6 a9 j! r) Z+ gbin2dec        Convert binary number string to decimal number' ~/ {. G3 ?$ U5 c: y; ~* X
    dec2base        Convert decimal to base N number in string
    4 T6 Y( v8 p. y/ E1 G4 V! p4 d  Ddec2bin        Convert decimal to binary number in string( F, ]+ V1 \# k' C
    dec2hex        Convert decimal to hexadecimal number in string7 g' j) r/ R' F9 `; U
    hex2dec        Convert hexadecimal number string to decimal number
    . }* V- R' @2 [+ A" q( z1 Qhex2num        Convert hexadecimal number string to double-precision number
    , Q) Z' A* Q% Z# P4 Vnum2hex        Convert singles and doubles to IEEE hexadecimal strings# W8 B" ~9 H9 i9 H, c# t1 W; Y
    cell2mat        Convert cell array to numeric array1 {- P! X$ c  J9 ~- k8 N9 v% J, S
    cell2struct        Convert cell array to structure array
    1 t; I& w  r% ~4 I8 c2 B) lcellstr        Create cell array of strings from character array( k6 Z. \* q. V2 o" z
    mat2cell        Convert array to cell array with potentially different sized cells
    ' m: w" L% B' c  {- {5 B1 m  X. n) Hnum2cell        Convert array to cell array with consistently sized cells; X+ o/ h2 A# R
    struct2cell        Convert structure to cell array
    : h! L3 |0 e! q& }4 ~; _  ]9 Q- U测定的数据类型2 w  ?* R9 |  X, F% T- D0 i

    3 k7 Y$ g' t: K8 D& NMATLAB 提供各种函数标识数据类型的变量。2 ~3 L! U; s5 k) g1 q
    0 o6 t# V& P1 p) j& ?
    下表提供了确定一个变量的数据类型的函数:$ V# a) Q% k! X# S

    - d( t; u  m* C函数        目的/作用
    + y8 D9 E, K. cis        Detect state
    : O7 ?  e. c; }) {isa        Determine if input is object of specified class
    % t; A% i" A9 z2 w. a. Tiscell        Determine whether input is cell array9 b+ m1 W, ]) E/ |# I
    iscellstr        Determine whether input is cell array of strings2 H' P, f/ i: I- k" G4 [7 U
    ischar        Determine whether item is character array. o2 ~' V5 w2 e; l1 ~$ j
    isfield        Determine whether input is structure array field
    ( h2 _1 B, r& c  c3 s" [; Hisfloat        Determine if input is floating-yiibai array
    ) R$ K9 i: d, J3 _9 i$ t3 \; Qishghandle        True for Handle Graphics object handles
      Y) f) ?( {/ O) L- s# a( k  misinteger        Determine if input is integer array
    ( _3 A' p& S0 S. B1 O! j/ ]( ^isjava        Determine if input is Java object
    % v2 U5 f( ?" N! t9 `islogical        Determine if input is logical array$ M3 j: |- ~% ^5 }3 T; T  U- p5 m
    isnumeric        Determine if input is numeric array
    2 n3 `. p* f7 O5 Jisobject        Determine if input is MATLAB object  U& q9 v% H' {- {5 }+ r* h2 Z
    isreal        Check if input is real array
    5 z# j) }, G8 f+ w6 {0 [isscalar        Determine whether input is scalar
    , I6 j, f. O/ P7 X3 ~! eisstr        Determine whether input is character array
      ^8 a4 N! I  Z; G& f# fisstruct        Determine whether input is structure array
    : N, j. j$ ]! b  Z$ H2 x' R/ Misvector        Determine whether input is vector
    0 I- M. Y6 \) m2 n/ iclass        Determine class of object
    5 E5 m) B; v5 b! g9 z2 Gvalidateattributes        Check validity of array! G! p$ y% a: W3 J3 B6 K" M
    whos        List variables in workspace, with sizes and types: e" I: I6 h2 B( h7 A
    例子: C5 `6 B' ^  C& ^5 p% o
    7 C- k( S' ?- w/ h7 r: ?
    创建一个脚本文件,用下面的代码:. H. U  s4 `6 A
    ( s6 m1 Y' G7 t" {3 q
    x = 32 W8 E* b+ s7 q: d. d
    isinteger(x)5 M# K8 b1 K% t3 J
    isfloat(x)
    / ?2 R- N5 c: H' H' _: |isvector(x). _  {9 c1 }# `
    isscalar(x), [. d; Z0 h8 `) e! D
    isnumeric(x)" F2 R: w4 h8 n' S$ P
    9 R9 d' k3 f7 ]: d- E" ?; l/ F
    x = 23.54
    4 _+ E/ n* s7 L! [+ t" Y1 f, Pisinteger(x)* N3 F- {' m$ m& o
    isfloat(x)! h: P4 {2 o/ }6 a/ U2 \
    isvector(x)6 ~9 C4 v- `6 t! a6 U
    isscalar(x)
    / d; ]1 I& J+ _( c0 Bisnumeric(x): `2 j1 w1 X$ A- N9 T' E- y" Y# _
    7 r- x# S  K$ d  \) t; J/ v8 |2 F
    x = [1 2 3]
    9 E; b& F! O' ]% m. c' n0 n( Oisinteger(x)
    # @2 _9 V/ V0 j" |" C& `isfloat(x)& ]( Y8 F1 w+ N/ {- D! I
    isvector(x)
    9 G8 B1 d$ V5 J4 {' N( @isscalar(x); K3 x; r: \& j: _

    6 f0 O/ R' @' a/ ~x = 'Hello'+ d" G1 O/ r3 w" o: h
    isinteger(x)5 i9 `( y- Q2 ^
    isfloat(x)
    # ]" |8 x- q# k6 s" Fisvector(x)
    ) \& B9 k' R( q8 L- f* f6 F) qisscalar(x)
    - q2 I/ A7 K$ E8 P' h7 yisnumeric(x)8 X0 V  u' r/ y: N5 b/ [8 |( W
    当运行该文件,它会产生以下结果:9 C2 g$ N2 S% ?1 t

    1 O% A9 ~* S  s# A2 vx =) s! p- J; H. G+ b% ]" t
         30 G% C+ s$ H' n) I- |  O
    ans =
    8 w/ W" T+ ]5 e5 b7 _. q3 L8 _7 b2 H     0
    9 r9 q2 h; B2 g: L8 \* n" kans =
    8 z; ~; l* ?# o  E     1. k3 R8 L& g9 O$ E4 a
    ans =' v0 U% W) j' w
         1/ y9 V2 X4 v% x% ^7 M0 H
    ans =
    ' @& M7 Z  V, Z7 v     1
    , d! A) v3 _3 @ans =' F1 w: y; ^7 r( `0 `: B* d
         13 Q2 n& F) a5 S7 t+ j/ H. o- A
    x =
    ( E5 S3 V+ d+ Z, N1 M9 t# e, ~7 R   23.5400
    : V) L$ y) R' z( H3 lans =8 x! }; s8 [. Z0 l
         0
    2 I! f0 R4 f9 g+ Y) jans =
      x3 |: J* f9 @7 Y- n9 e     1$ F( W8 ^# F& Y1 q7 e- U) a
    ans =, Q1 B4 U7 T3 K* O+ K
         1
    : V# r* S5 `; f  T! Tans =
    : g+ i" P' ^1 M9 _) F     1: r& P, o7 [. _8 R( w
    ans =
    2 n5 ], P) k- c/ @, x/ @( O     1$ a2 d8 q1 G' x& y+ `3 |2 \1 a. ^1 T0 `
    x =+ ?  m9 K/ o; h! f1 h( g$ t! v9 S. K
         1     2     3. N, x" ~" _7 T9 |" D- u1 q2 B& G
    ans =
    % k3 X3 u- t9 Y, t: C7 [     0. o7 R! I) F- L! b3 T
    ans =
    6 o- `: \/ q  Z0 c) I( ]& Q     1; l+ V0 e- r- I. k6 P. p
    ans =; N% \+ f3 W+ L6 G) Q, s3 l2 ~
         1" D0 E  n& u' m5 X' X3 O7 n
    ans =8 s) S: f# P( J" `% D+ p
         0
    ; |. d8 H$ [$ S3 b: s! Zx =* I/ Y6 j( Y# B
    Hello* c2 t1 `8 @. {) w+ Y
    ans =
    9 T4 @$ c# A$ D6 C- n+ K4 B     0! r) |  {- C2 @. n$ {
    ans =  v0 l; g0 l# L9 c4 n
         0
    4 R5 c% z3 A* b3 a, O3 k+ gans =
    ' b( U/ o5 R1 `! z  y7 f     1
    1 A; D5 `9 L. Hans =; d5 n; I* w6 A; o! g! Q6 }0 g
         0, y8 @1 s" p) c! i7 j+ h
    ans =
    ! Q! R' N- h( p, |1 |3 g1 s* O     0
    ; b4 A% N+ Y) B8 \
    $ \4 K8 p2 A8 `) ^————————————————3 w* B  k' Y2 M; s! M" i
    版权声明:本文为CSDN博主「Phil__ming」的原创文章。
    " d0 F7 V$ U7 L/ o$ u0 l3 S. r! T原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575' V# ]- v+ t2 g' @2 b* d7 \
    9 P, f8 E1 w5 j$ Q. w

    : d; s6 F& `+ l
    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, 2025-8-3 04:09 , Processed in 0.300397 second(s), 56 queries .

    回顶部