QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3489|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。
    9 n" }, }6 Y! n( @$ U0 G$ N
    7 X$ Q0 e- n! k5 ]; I9 L# N7 T9 e如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。' }  O3 g. e  ~, Z! y
    0 z7 H  J5 J8 f1 c9 u
    例如,
    / I9 ^( P! J3 h9 X: U) g* A* ^0 h- N
    Total = 42
    8 x  O* a! z: {3 ?" `: m上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。
    : f2 J- R2 C6 }9 X# k4 V* N2 u7 c4 U+ p. m" K
    MATLAB中可用的数据类型
    0 \0 [3 ], H+ V# U) l# ^. _% V
    4 K8 p8 R* e* ]/ C9 RMATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。
    , F! C8 I6 }- W
    / T1 y, t* A7 b' [下表显示了在 MATLAB 中最常用的数据类型:7 q: A1 }: e% y0 D
    / c$ C4 T! C) X, C/ B( \% J
    数据类型        描述
    + s9 |9 {- @2 Eint8        8-bit signed integer
    6 Z3 W2 j1 }; {1 ]2 X) E; @6 }uint8        8-bit unsigned integer
    0 }* ]# k4 |( {) W/ i- ?$ a- j0 Q8 s7 {! Xint16        16-bit signed integer" \( i. W5 G0 z
    uint16        16-bit unsigned integer6 M1 j" _. j$ Z+ I; e% m, D
    int32        32-bit signed integer
    + _. X- {0 u% d3 t. duint32        32-bit unsigned integer
    : V2 P3 g( p3 [* L) @int64        64-bit signed integer
    $ b% M7 C2 j. N6 t- Puint64        64-bit unsigned integer5 j0 F& N8 C; S/ ~' k" p- i
    single        single precision numerical data; ], F: c! T5 ~  a
    double        double precision numerical data
    $ c: j' z" U2 ]* Z$ [logical        logical values of 1 or 0, represent true and false respectively
    , }/ a, a1 S6 c0 e+ S* pchar        character data (strings are stored as vector of characters)" a% C  n0 d; o; Y
    cell array        array of indexed cells, each capable of storing an array of a different dimension and data type
    $ x, i% W: e: G9 Rstructure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type# @: L& K7 I3 ^$ R9 [4 L, c) V
    function handle        yiibaier to a function
    8 c8 ]" `4 D$ O5 D/ z+ W' s9 buser classes        objects constructed from a user-defined class# S+ h- ^+ J3 R
    java classes        objects constructed from a Java class7 ^( e$ W- h. o; K3 x! K
    例子
      {! f/ a2 u' t6 B9 `- S" x7 a0 q. ~, E: K+ a: d
    创建一个脚本文件,用下面的代码:( x' L- |/ s. e/ g6 H2 S0 H% ^

    1 {; }4 \% H. j$ H' A) [% ] str = 'Hello World!'; G8 q' G% c% ]: I( w
    n = 2345
    8 v) ^6 n4 @: M6 {$ F' n" C  qd = double(n)
    , Q- L2 e2 I% A/ f/ Q' g5 ^un = uint32(789.50)
    $ M, q" n) M0 prn = 5678.92347! [! @  \0 `. ~/ l
    c = int32(rn)
    ; K( [7 O! w4 t3 q0 }2 q8 N上面的代码编译和执行时,它会产生以下结果:
    0 |5 B. V2 i" Y* S% r5 w  p2 g$ Q: L
    0 R0 Q7 Z: c. f1 xstr =
    / r: b" ~0 x. U8 A2 PHello World!
      V  D# |, X8 hn =
    1 S, o* m- Q& b   2345
      [! p3 x0 x$ d- @+ md =( d8 W; V# y. J: d& v1 s
       2345) \! ]4 d1 t1 Q6 d- z
    un =4 D% {) v0 z# A3 r$ K
       790
    3 {& v2 \, T, f* Crn =( m- ^. g% K! [. W( T0 ]+ l  U
       5.6789e+03
    ' c- W+ {" e% {. Dc =1 }5 [) U1 C$ e( B6 O
       5679
    0 O. I1 `5 q2 S: {数据类型转换. z1 W3 R) W1 e) k, J, E3 ?
    , D+ e6 C6 f' a6 r" E
    MATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:
    ( a/ g, D9 @( F6 M! h
    2 C; r. i3 m# h0 X函数        目的/作用
    # p5 E4 h) [" c# Fchar        Convert to character array (string), @- s& L. F1 z6 C; N
    int2str        Convert integer data to string) ^3 f% E3 D3 Z
    mat2str        Convert matrix to string4 ], ]) i$ X0 h2 }) m1 Q. A
    num2str        Convert number to string' }# C) U9 ]! l. v
    str2double        Convert string to double-precision value# M! F1 v* [0 o$ ?; L8 w2 h8 t
    str2num        Convert string to number
    8 G, P* Y, O' pnative2unicode        Convert numeric bytes to Unicode characters
    4 I: j; J7 ?7 Zunicode2native        Convert Unicode characters to numeric bytes
    6 B0 j7 u0 n8 }. qbase2dec        Convert base N number string to decimal number
    / Z6 {! X1 O; T1 Gbin2dec        Convert binary number string to decimal number5 c6 M7 B  E& R2 }
    dec2base        Convert decimal to base N number in string" s3 @1 f, W# Y; }* K5 _1 |+ A6 `
    dec2bin        Convert decimal to binary number in string' Y. o" f9 v. y
    dec2hex        Convert decimal to hexadecimal number in string4 }1 r( f, q- ^3 E
    hex2dec        Convert hexadecimal number string to decimal number
    5 r. U3 ?$ N& @# [1 Khex2num        Convert hexadecimal number string to double-precision number
    & Z3 V0 E4 g4 S2 @& v4 Z2 c1 Knum2hex        Convert singles and doubles to IEEE hexadecimal strings! S! c5 K) w/ B$ Y8 U4 v
    cell2mat        Convert cell array to numeric array  v3 |: |& m0 C; @
    cell2struct        Convert cell array to structure array
    & {% [" \; @! }, L* ]cellstr        Create cell array of strings from character array
    " c: \" C; {1 p6 vmat2cell        Convert array to cell array with potentially different sized cells* t' y9 ~& B" j0 u% |4 [+ ~( }# _
    num2cell        Convert array to cell array with consistently sized cells& h5 m5 W! S( z) M" ]$ @8 x
    struct2cell        Convert structure to cell array
      z1 p: w+ W& {; i# b测定的数据类型4 v( i5 f' D1 }$ Q, `4 N

    / J$ Z( T' l" R9 l9 }! CMATLAB 提供各种函数标识数据类型的变量。
    8 Q0 x9 Y/ [. [7 N0 U" @9 J3 x
    , ~% H3 R1 }  \2 w- L# X' [下表提供了确定一个变量的数据类型的函数:2 Q8 Y0 l7 A5 y4 `, \) f
    # }8 a; V6 ^- E
    函数        目的/作用
    5 e/ M1 w1 K6 V$ m) B1 Iis        Detect state3 P+ `! u. h! q* i  H
    isa        Determine if input is object of specified class
    * |7 e- P# ?+ I  U1 t3 a) ?; M# uiscell        Determine whether input is cell array- d  m* Q& {; c2 F& r" L3 L
    iscellstr        Determine whether input is cell array of strings
    9 m* A, J% N: V% T# K- U, Uischar        Determine whether item is character array# ~7 b* c- A: T7 R! i
    isfield        Determine whether input is structure array field
    3 S5 Q+ Y3 D# P- B" I6 l% E3 kisfloat        Determine if input is floating-yiibai array# V4 R0 s8 x! L/ @5 @7 e6 O7 i
    ishghandle        True for Handle Graphics object handles7 A- o! D$ \) M9 k, l5 u3 d$ S* k
    isinteger        Determine if input is integer array
    9 {$ [4 }1 M$ x- q  K1 C1 p% cisjava        Determine if input is Java object, z8 J' [$ A# J! R$ O3 Z: g+ M" M( c
    islogical        Determine if input is logical array
    ) S. U3 ]5 O7 o) Y1 z! `( c% ]' Nisnumeric        Determine if input is numeric array
    & I& m) B$ I* i0 eisobject        Determine if input is MATLAB object2 |' V3 e6 ^8 v# N9 w# c8 }: n
    isreal        Check if input is real array: v0 W% e3 L: A
    isscalar        Determine whether input is scalar( u6 |3 W# L" N' O4 o( t
    isstr        Determine whether input is character array$ l9 i! [. s* \/ h; I3 J: m, g
    isstruct        Determine whether input is structure array' p1 W2 I' V' f* p. n
    isvector        Determine whether input is vector  E# Y9 y9 H! f5 ?9 ]
    class        Determine class of object: S7 H2 \& Y# F
    validateattributes        Check validity of array# v3 ]  j( T% ?: b- K! h
    whos        List variables in workspace, with sizes and types$ Q% L) t( Y& |* c4 ?1 G" m6 _' [
    例子
    0 l9 T/ z3 k: ~1 c, k" m" j. Y) g
    # q* l' n, f# f- J) }7 ~  K' \创建一个脚本文件,用下面的代码:* b7 p* n$ ?: n( o" v+ m
    + d$ I$ p1 e2 L9 o7 e* [; A' }9 O
    x = 38 f! |! V, ?( Y
    isinteger(x)
    4 b9 o3 E8 u$ J" y5 ~isfloat(x)  e% U6 ~- p% y+ o# ^0 a
    isvector(x)
    2 I- F+ p0 w% [. j* g/ v2 Kisscalar(x)% ]! A* H- w6 V  w% j% v  M6 L
    isnumeric(x)* c/ l8 d" g+ i" i/ l  R

    5 G/ e, h4 b* e8 ?x = 23.54. F! h( A! C0 \1 J9 U4 f
    isinteger(x)
    ( @) O2 ]; _1 [+ d& {4 `. p; Uisfloat(x)5 u1 l) D- A, {7 A, [1 K( w
    isvector(x)
    - c' Q( x7 Y$ @5 m1 f: l- K) Disscalar(x)
    5 o3 [  Q0 s2 F& [8 L5 q, e# D" _/ Zisnumeric(x)
    3 }2 k" S0 t: [; P
    $ r3 b) n0 i8 Q; ?x = [1 2 3]
    6 f# H2 F8 Z5 X, Cisinteger(x)
    4 r; ~5 x+ P9 _) l- sisfloat(x)
    ' i* x/ I7 z6 Lisvector(x)# ^1 s* |+ D' z: V  {
    isscalar(x)& `% [, D9 h+ P3 f/ V4 K7 N, Q" T

    3 z4 C& N6 a' l* {) j, m" _x = 'Hello'
    1 ^! S" B, }+ O: Bisinteger(x)
      Y! T/ D5 V9 a2 M% G% l! `- @isfloat(x)' _; X; v) W1 c0 E/ e4 {+ [( A8 m
    isvector(x)
    - p' Z# k% H6 g% |. J" d% yisscalar(x)
    % r* C8 X( A8 g! S. k6 |! zisnumeric(x)
    # I% E. D" k9 V当运行该文件,它会产生以下结果:
    ! l1 j& \8 \5 h. B0 |! o) h; c) h4 g' T( r  e0 }4 v7 G  i8 z0 M
    x =
    3 m- _, _' Y5 m# ?, s     3! ]  w5 X( u& E9 Y: Z
    ans =6 z2 ]) Y% R) E' g% H* H3 m1 q
         0
    2 I* i: I3 r( d( tans =
    " U/ P6 ^& h; c7 L     1
    7 y9 w1 {5 ^% v. r+ I4 Fans =
    8 ~: K9 K9 |" ^. f, {( R' ^# q# c     16 t4 T; q' Y4 n# V: c" W0 S. h
    ans =
    9 `1 [( w  w5 T     1
    ' W4 j& R  i5 b  y7 a8 A1 {2 Z& Qans =+ Y& Z; m! {- L
         1" K8 {- u; y' o9 {
    x =
    # c/ G2 i8 ?1 t$ [   23.54006 p0 o: X6 b$ f6 s: x
    ans =5 m# H2 Z3 z$ e( u2 p8 @4 O3 D
         0) s# T) B% D, J% a
    ans =6 ?2 r3 n/ m' \: o/ b0 e
         1
    4 r; g0 ?1 o  y# D7 mans =
    " Y  _" t" H) y/ N2 C8 S     1! K" ^8 \/ d: k+ J% \
    ans =
    0 ^! S. X1 ]  e* {     1
    & L% J" k- J3 m$ p/ Hans =
    " Q, ^, Z4 u0 }     1
    6 E" O* q1 q8 ?# Jx =
    ; D! o4 K6 I+ K: ^( x' d( ?     1     2     3
    . U: `2 G, q$ J9 Z8 v/ L! ^7 @ans =
    + x3 d  m, g; E# @) m# V6 k; f     0
    " P3 B9 i. H2 K! F' t. ^& v9 E2 Sans =
    # r4 @! T" J' w+ x  i+ Y" n( z     1
    . a8 t* O2 X# p4 Q& H7 ~3 ~ans =
    ; _4 B2 d7 t0 b5 ]0 H* Y# R! Q( {     13 I1 r9 p5 S5 l
    ans =: V( t& K9 B$ y+ b- ^
         0- |2 _9 {; S9 R2 R% K, V
    x =
    " i. `8 ^  P2 y1 D1 ZHello) A9 X9 J+ P6 B/ J3 s& q# f4 ]
    ans =
    2 b" P1 \# K% }     0( Z1 s! P% r% l: p6 [! c
    ans =' \2 |( @2 {5 M
         0
    ( L3 Y4 e5 e" J8 E: x& X0 A9 Mans =
    4 @5 c! g' r/ j# |5 G     1
    ) q. L# K+ e" t" r* Q# fans =# Y& |3 E* y" ]  ], `3 ]* L/ d! |
         0
    8 |$ ~( C/ F! |5 ~7 [ans =
    # b7 o9 D: }# F, C     0
    ' R/ {5 I5 m" \2 ~: J. j/ O% Y
    9 w& X4 {/ u; |————————————————% @+ r  l  G& B7 j: J! ~2 N& P
    版权声明:本文为CSDN博主「Phil__ming」的原创文章。% F9 g+ \' A5 V6 D5 ~
    原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575
    ' {( f$ e' y6 v- x
    - \, g# m- }' t: j8 m( H2 x$ i' E- B
    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-9-24 17:30 , Processed in 0.643808 second(s), 56 queries .

    回顶部