QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3563|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。5 o; M. X: }9 d2 ]% X

    , w  I4 X3 a: T, ?3 Z% \4 e如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。8 t; O- Y* K( {' Z: E  n" c* ]
    3 z4 K9 R8 a" _; I8 z
    例如,
    $ I; k9 _4 ?% Q( w* [: U, a  X
    # `- T* D4 w8 }$ RTotal = 42$ _3 y# a6 B, V* A
    上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。
    ! K. E) V2 A; W5 ^2 Y3 Z, u
    ' P7 R- y; o6 m" z/ t& TMATLAB中可用的数据类型
    9 t* L- R3 `' q( U/ ~+ _; t/ _& X. a$ @
    MATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。) M( q+ }8 K8 n. W# ?) ?; z

    0 G" X$ I' `9 J4 ~; ]下表显示了在 MATLAB 中最常用的数据类型:$ _9 ]* p  O+ q$ I1 L1 ~. [# t, Q$ Q; P
    6 X/ j2 M2 [* S
    数据类型        描述
    5 a- T& B9 b# y: Y- @* Tint8        8-bit signed integer6 t* W: T1 R1 O$ A& f* N* L* [
    uint8        8-bit unsigned integer; \# h& _4 t, g7 O. ]3 v3 s
    int16        16-bit signed integer  F) _! ~- O* _8 }7 F0 }* \
    uint16        16-bit unsigned integer
    0 k2 l4 X! F( e$ B# Yint32        32-bit signed integer- C* c2 x/ _. U; A. f* ]& |
    uint32        32-bit unsigned integer
    ; J+ t- b0 L$ V( e- Aint64        64-bit signed integer+ U. _. k7 E- |% u
    uint64        64-bit unsigned integer
    4 _) W% R# X9 d1 xsingle        single precision numerical data' [5 M2 _0 q% m1 u$ ^% E
    double        double precision numerical data7 l$ G4 t( O- x
    logical        logical values of 1 or 0, represent true and false respectively
    7 b9 |( V/ u$ x+ ]7 `0 cchar        character data (strings are stored as vector of characters)
    ( T, o3 n! e* Bcell array        array of indexed cells, each capable of storing an array of a different dimension and data type
    : ~7 W4 k3 R) z7 z, ustructure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type2 r3 p6 F3 X0 e9 c3 L- W* B& S1 N
    function handle        yiibaier to a function
    7 J) O' l: o" Q8 V1 Guser classes        objects constructed from a user-defined class
    $ f; _' K! T; x0 g4 U+ ejava classes        objects constructed from a Java class$ D9 S! l$ w  }( g. ?8 D( i
    例子0 \3 B8 L/ m/ g1 L9 p1 Y) Y: y

    # \7 ^+ W8 Q# Q+ e创建一个脚本文件,用下面的代码:
    1 l5 S: y" b* f+ P* j! `" e* G, W& n6 F; l4 z7 g
    str = 'Hello World!'3 g, w: r& U; l2 u
    n = 2345! }5 Y: k$ |  ~* u
    d = double(n)
    # v3 D0 l8 ~- z7 }$ o7 {un = uint32(789.50)3 g5 e- |; _8 O/ u/ `3 i3 m
    rn = 5678.92347: f6 x9 a( E! `5 d
    c = int32(rn)0 d! U/ ~* w0 U; x4 W
    上面的代码编译和执行时,它会产生以下结果:
    . R, r% i+ O+ [# s
    , r. g$ X# X# T: K2 X5 n! p' }str =
    8 _/ Q: ]. O5 f& u: f% |$ ]- q% O9 DHello World!! |3 o7 n$ ?* A9 E1 G
    n =
    2 t+ @% @5 x+ K- e   2345
    . |! b# r* z. ?- T  S- ^d =
    ) O* F& S4 ]: u   23454 j7 A' ^% b- I8 i
    un =0 q" N$ }) }* }5 P& {$ H
       790
    + ~* B. [9 \+ N9 M8 n$ Lrn =
    ( h7 n) D. X/ o) o6 }" i! e5 E' O   5.6789e+03
      s# L1 n. o4 @1 c2 A  x' m+ lc =, j' c  U3 x# c6 O
       5679
    % h5 x5 T. g" [  s+ G( H2 r数据类型转换* V/ \- I- d) O

    ) c2 f; f, j) r/ FMATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:
    : y0 y5 |5 c7 f4 `* K! n' Q4 v
    1 T1 a) }3 A7 v! Z函数        目的/作用
    7 ~  U- Q; F+ G) w+ M- C3 ^6 Pchar        Convert to character array (string)' l5 c! K2 u6 ]+ G) {) i6 [  f+ p6 g
    int2str        Convert integer data to string9 v  Y" z$ e1 D3 o9 K
    mat2str        Convert matrix to string- A* r: Q) E8 n) H$ U3 Z8 H
    num2str        Convert number to string, |) [0 ?& O/ ~! ?. O! m: Q
    str2double        Convert string to double-precision value2 U& ~+ W* G9 G
    str2num        Convert string to number
    + F2 A; ]( n( |6 Nnative2unicode        Convert numeric bytes to Unicode characters
    ) b7 A. M- L4 Q0 S0 Z, n+ k6 Qunicode2native        Convert Unicode characters to numeric bytes' h& _5 w. D( d! u' b
    base2dec        Convert base N number string to decimal number6 c. L- }5 r( R5 l" a# L; ]' H
    bin2dec        Convert binary number string to decimal number8 P+ N" F' K2 ^3 s
    dec2base        Convert decimal to base N number in string
    ' C7 s- k" P2 b- |# F6 ~dec2bin        Convert decimal to binary number in string" G7 \) y8 I! X  O  A
    dec2hex        Convert decimal to hexadecimal number in string* u+ H- G+ @% }* M+ E* d6 r: T
    hex2dec        Convert hexadecimal number string to decimal number
    $ ~5 @7 n' V9 s- C5 h  I5 N- D/ ehex2num        Convert hexadecimal number string to double-precision number
    : i% w8 z5 z% Gnum2hex        Convert singles and doubles to IEEE hexadecimal strings- I+ N' o% E  l1 X
    cell2mat        Convert cell array to numeric array
    ) P. r" G6 t* n" [cell2struct        Convert cell array to structure array
    + }' [+ m" _2 f& ycellstr        Create cell array of strings from character array
    ) r3 \4 F- n: y7 qmat2cell        Convert array to cell array with potentially different sized cells* Z3 e' N) e$ T/ v0 L! m9 T
    num2cell        Convert array to cell array with consistently sized cells
    ) p7 v  i2 B5 Y" ?4 dstruct2cell        Convert structure to cell array
    # j& D& D+ n* R* e2 D$ ~. d  O8 i测定的数据类型
    6 o+ t/ Q) h  P; Q  `9 f" K3 y4 X8 X, L0 A/ C
    MATLAB 提供各种函数标识数据类型的变量。
    - }5 `/ T- @/ `7 ^+ F
    0 i5 ^; a2 g1 b7 g- ?: G. F下表提供了确定一个变量的数据类型的函数:' P& g# d( u! U- f% \! H
    9 T5 l- C4 \4 M5 w7 M. e$ i
    函数        目的/作用
    , i( v- H& A. j; Uis        Detect state8 ]5 k, v6 E+ l' G' u2 ^3 _* Z
    isa        Determine if input is object of specified class1 B' R- G  Q& T; I
    iscell        Determine whether input is cell array% F0 x: R/ p% ?. T- n
    iscellstr        Determine whether input is cell array of strings
    & m: H- [4 r) B+ vischar        Determine whether item is character array
    + H! E2 e7 z# p. Z: S+ Wisfield        Determine whether input is structure array field) {0 m" n: q6 f
    isfloat        Determine if input is floating-yiibai array
    2 l6 ?7 a9 z# }4 H! y/ g0 dishghandle        True for Handle Graphics object handles
    - ?9 R. c! ?7 ^4 @- l/ W7 _5 k: l; sisinteger        Determine if input is integer array
    6 o0 \& i6 Z! [# `isjava        Determine if input is Java object
    + w; P& N4 [: g8 Yislogical        Determine if input is logical array% h% _! G  V! ^7 x  \0 b3 W
    isnumeric        Determine if input is numeric array
    0 G0 h7 U: u1 t5 z( N1 Jisobject        Determine if input is MATLAB object
    7 J/ v* |, t4 G9 G$ \  q% H) Lisreal        Check if input is real array
    , q. c" V4 g, _9 f6 s! T: D" disscalar        Determine whether input is scalar
    , m3 i4 r9 Q2 [) ^isstr        Determine whether input is character array
      v. q' o% S5 a( `isstruct        Determine whether input is structure array
    + r/ G1 f/ e% oisvector        Determine whether input is vector1 I/ }5 L- R& d/ ?. F# [- z
    class        Determine class of object
    3 w) i: y* g8 z1 yvalidateattributes        Check validity of array
    9 x1 d$ J! E& ], W' ^5 owhos        List variables in workspace, with sizes and types
    : Q3 H9 H' [+ A% g( V例子
    + ]$ }3 g! r2 ~% i3 p' R4 J7 n( i; ?: i
    创建一个脚本文件,用下面的代码:
    $ T; ~3 ?2 G5 i* ]" G) M
    : R  D# v! L0 B& j# u# Px = 3
    6 x3 C% C' S) q$ {isinteger(x)0 l& ?8 x4 r6 c
    isfloat(x)
    2 W$ i- d# `8 S8 y' uisvector(x)9 u, x$ V, u" C2 X8 n
    isscalar(x), V6 d  h- d% w" M
    isnumeric(x). N. p5 b% K5 y2 X1 S
    ; g  m. i1 g8 n2 ^; t+ v( A* h, j
    x = 23.54
    % L* R- p3 N5 W1 m# {isinteger(x)+ H4 Q) [8 M1 Z- ^/ o
    isfloat(x)) x  c" e/ g" ~/ Y6 R
    isvector(x)
    . u. z, _1 Z( p( V, h2 |: U5 aisscalar(x)2 ~0 P1 u& _% v% O5 L6 h
    isnumeric(x)
    & i" @$ }3 d: ]4 a: S+ K. N  G( `) f$ j
    x = [1 2 3]
    0 x" ?, ?/ f1 `8 {: Kisinteger(x)" V# a8 P9 Z% ]) Z. N
    isfloat(x)
    4 {: J( W, [4 w: p( X4 Z, {4 wisvector(x)! X5 M! b* P$ _$ P0 s
    isscalar(x)+ h4 Y8 f/ X* a
    1 N% T) S: a5 \( @
    x = 'Hello'
    * j+ |3 g2 @7 P3 l3 Xisinteger(x)
    6 y: v0 W6 B8 Misfloat(x)
    ; r) w" N4 i! t  P9 [" P6 ^! misvector(x). f5 v! |2 l. t1 A
    isscalar(x)
    ' S4 [3 N8 b# ?; uisnumeric(x)
    ) r1 U$ b* W$ q2 X7 P1 ~0 K* B* l当运行该文件,它会产生以下结果:
    # E3 q, ?/ l  U: {% m4 C
    : w% S7 N( y- K- c3 k3 ox =
    & z" U  e: Z2 K4 V$ E: A  o- l     3
      P1 o1 s0 ?2 j/ mans =
    ! }% J$ V2 H; a# V& h, Q9 Q% i) f     0. v4 j+ ?. o: f( E
    ans =7 h6 Q/ n- J8 u/ i3 b7 C0 o
         1% h" `, \* V' g
    ans =
    - I& e* F  x, C1 s. q     1  l6 e  b# E8 r* u' E* O
    ans =
    1 z0 t- b- h; m% e     13 q5 u" H+ I8 c9 C6 |: J3 i
    ans =4 x( h( k" d. v5 U' p
         1. _6 `) O% o7 g6 \3 F5 f1 h3 j" K$ p
    x =
    4 q4 E9 p: k7 [8 x   23.54005 t- H. [# n; ?( o
    ans =
    1 z( L3 h8 ~" w     0
    , \( E7 k6 `. _5 x$ P5 Rans =
    2 F9 `, M! N: Q     1
    2 p" p9 L) Q6 h+ h. _7 Kans =5 `/ }! O" i, o1 v$ ?2 J! ]
         12 \5 u6 O0 R3 a( c/ t
    ans =
    ) [& `! q$ d( \5 M     1: k& x4 k7 ^$ Y: R  G- J( X
    ans =
    8 a' b/ h( F3 e, S' @     1
    6 w  M4 }! V% \x =) y* x+ @3 d6 ^, [6 d; Q
         1     2     3
    * K+ c6 _' G' h6 C; {ans =$ w- P. U  i6 k2 K: v" R* Y6 q
         04 L' y" l0 Z1 H  X
    ans =
    % L% s# L3 ?- v) z     1
    - F4 `6 \. h" ~- I# Lans =
    : A$ N7 |" I$ J! V     13 m+ z4 l; w7 b) [7 ~+ m
    ans =3 k' Y; j# x3 g1 i" A5 E& e
         0
    8 d; V1 r0 Q- Q; ox =
    7 Z* b& [" M/ M9 j3 Z/ H% n9 DHello+ {  N* I! p# P& V4 Z
    ans =" ]3 O& _# K5 `' S6 \
         0. q7 k" w. {+ I( q/ s
    ans =
    8 m$ l& q( [9 Z1 k3 R4 f4 r# \     0
    2 u: v7 }0 z" G, g+ m" V% i9 n& |ans =
    - |4 B9 q7 }1 D# a5 [) k  K+ D     1& n2 i2 ?5 ~( Y+ e& z! }! y
    ans =
    7 a  Q& g9 g2 f# P     0$ b7 ]' L  e. H6 D) e
    ans =
    1 M4 m( c2 ~0 a3 D, u6 S, g     0: D) J1 ?  c' K' M
    6 I, a3 D  k8 h, b( l
    ————————————————
    . i# c5 g* v" G. q2 o版权声明:本文为CSDN博主「Phil__ming」的原创文章。3 Q$ I  h( B) [) `/ p- S
    原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575
    ! d: v* {3 P& w& \: q6 w6 x  v  B
    $ Q8 K% T( X; h/ g- E; E' r9 q
    2 s2 c- e3 S7 y" l  e; G& h% ]
    zan
    转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信

    0

    主题

    1

    听众

    59

    积分

    升级  56.84%

  • TA的每日心情
    开心
    2020-3-22 18:15
  • 签到天数: 14 天

    [LV.3]偶尔看看II

    邮箱绑定达人

    群组: 数学建模美赛备战群组

    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册地址

    fastpost qq
    收缩
    • 电话咨询

    • 04714969085

    关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

    手机版|Archiver| |繁體中文 手机客户端  

    蒙公网安备 15010502000194号

    Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

    GMT+8, 2026-12-6 16:09 , Processed in 0.141483 second(s), 57 queries .

    回顶部