QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 3423|回复: 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 每当遇到一个新的变量名称,创建变量,并分配适当的内存空间。# [! X" |4 G" I/ C2 `& Z! H- q3 v
    " ~, g8 O/ v7 C5 H
    如果变量已经存在,则MATLAB替换以新的内容的原始内容,并分配新的存储空间,在必要的情况下。- }& o. B8 M: P: _

    ! a2 y& y2 R# O8 P例如,
    : C: ?* ?; V! s$ Q, ~! |+ E. f4 l( U* e  [2 B  s6 X% j* ^
    Total = 428 h6 O% [1 [! _% w- T/ c$ P+ H- p
    上述语句创建了一个名为“Total” 的 1-1 矩阵存储值42。* I7 K9 s: ]  k& H+ v: w+ a! d
      E: v& i: Z$ A5 A5 r
    MATLAB中可用的数据类型  P- t( [% B5 i0 n- [" T6 M

    0 I1 `. n0 m, z) n, Y" K' gMATLAB 提供15个基本数据类型。每种数据类型的数据存储在矩阵或阵列的形式。这个矩阵的大小或阵列是一个最低 0-0,这可以长大为任何规模大小的矩阵或数组。
    ! s! w8 x( r; Y5 C) C9 W: I* h8 J5 o. V+ d2 \. K& y6 h% f+ a. F
    下表显示了在 MATLAB 中最常用的数据类型:
    , e+ Y: \- K" |6 b6 A2 x) K/ v
    7 A9 C) J! J* E2 P数据类型        描述+ b0 G0 y8 W9 r7 N0 X4 a
    int8        8-bit signed integer
    ( j1 `, \, D% p3 [/ N( suint8        8-bit unsigned integer/ C& _$ C# O  L0 U
    int16        16-bit signed integer* N  L, C; f( N$ A7 F; K- c/ n
    uint16        16-bit unsigned integer
    ' ?; a/ R! R! ?, c3 R7 bint32        32-bit signed integer
    , i5 W' u* |0 ~$ F# T8 N- huint32        32-bit unsigned integer
    9 _& a, x( _+ ^9 I% D6 U- s9 Nint64        64-bit signed integer
    8 w) N0 |! r5 c; r3 Ruint64        64-bit unsigned integer6 V- V, i2 y2 n; x; d- z
    single        single precision numerical data$ O" l) c3 {; |7 z! p1 A9 n- x
    double        double precision numerical data
    ) u# w7 B8 |* k. w# M/ ological        logical values of 1 or 0, represent true and false respectively, x6 P& y! ^$ b5 s7 \; h
    char        character data (strings are stored as vector of characters)$ L9 O0 H# f1 @% Q, I: L! l# G/ F  Y
    cell array        array of indexed cells, each capable of storing an array of a different dimension and data type! ^0 c8 s) P7 T8 e; X8 f- W
    structure        C-like structures, each structure having named fields capable of storing an array of a different dimension and data type0 P7 p. f* v6 b% Q
    function handle        yiibaier to a function
    8 r6 P( s& @) D, m1 \user classes        objects constructed from a user-defined class  ^5 D  e- Y: j7 M1 W  X) Z
    java classes        objects constructed from a Java class
    ; l$ J6 k: u( U* G/ V: i例子5 a; E! S2 t0 g8 ~/ r4 w5 C

    9 u- @$ e- p8 j+ h! z& ]. a创建一个脚本文件,用下面的代码:
    ! E5 F2 i/ V, d1 l( W  a2 I5 A+ ?1 s1 ~. T7 N% V2 g0 K( a
    str = 'Hello World!'
    7 F7 ]- i2 d* \+ a* \! N/ Sn = 2345
    0 J2 |( {0 i' p) Z$ _: {, ^d = double(n)
    3 n7 B6 b8 Y; x% c4 u4 ^9 run = uint32(789.50)! h3 @, ~, V6 E* u5 [! l! O6 B
    rn = 5678.92347
    # H- S2 w0 I5 j3 y% a. _9 Uc = int32(rn)
    8 N  s: W" W: f& {  u' T上面的代码编译和执行时,它会产生以下结果:9 T5 C1 r. w- @& h8 ^

    " `' g$ {. _4 E6 q5 X, istr =
    5 E* P  \- c4 \0 `: m! c/ x* qHello World!: g; q5 C/ E! @2 t4 D. c
    n =% I' ~% T% \! c' }5 U
       2345
    3 t) b# y3 m+ J& V& ud =
    6 F6 X3 b( V# k7 [" H# |, T   23456 k" q/ T7 O  @2 G5 T9 G
    un =
    + _: w9 {2 W, {, h! t/ ]% u   7909 a: B3 d" O# T% M
    rn =
    7 K+ t( f) i( D" F: _4 ?. f   5.6789e+03' E; F: d0 M5 G% u4 R+ V0 D
    c =; E- `5 E" Y, k1 R8 t
       5679+ q# ]0 N1 C+ x
    数据类型转换
    5 N! f0 O6 V6 e- [8 f
    6 |! W8 o6 L( |! i! t! H' hMATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:
    $ ?% l" B7 P  q* _- d5 _! V, {, m  }8 `/ b/ s
    函数        目的/作用0 I% a+ K" K2 P1 d0 X! h5 q2 w" s8 Z
    char        Convert to character array (string)
    6 s4 a* U) I5 M  Tint2str        Convert integer data to string9 z9 B6 i) d" |0 r5 u
    mat2str        Convert matrix to string3 @; v4 G% ?0 [7 B* @  T% h+ C
    num2str        Convert number to string$ X' i: U% h, S( _  o1 Q
    str2double        Convert string to double-precision value9 G; I/ }: b& Q2 q6 ^, h# c  b
    str2num        Convert string to number/ o+ w. e. q+ j1 v
    native2unicode        Convert numeric bytes to Unicode characters
    2 d# L5 k1 T* L9 bunicode2native        Convert Unicode characters to numeric bytes3 i4 h2 v( @4 |. p# r
    base2dec        Convert base N number string to decimal number
    7 ]- U& H, V4 zbin2dec        Convert binary number string to decimal number, |) S8 j8 V4 S$ Y  l5 i' ?2 Q
    dec2base        Convert decimal to base N number in string( K! K; |( c- ]6 o! g
    dec2bin        Convert decimal to binary number in string! `' U/ T) e  T7 n  j
    dec2hex        Convert decimal to hexadecimal number in string8 ?5 Z, b6 E7 D
    hex2dec        Convert hexadecimal number string to decimal number
    ' K3 b( F1 @; d9 ?7 Ihex2num        Convert hexadecimal number string to double-precision number
    7 J/ R7 G( H, g/ Fnum2hex        Convert singles and doubles to IEEE hexadecimal strings
    ; p# A7 k: `- `cell2mat        Convert cell array to numeric array
    % _& x' S" w8 r# \) Wcell2struct        Convert cell array to structure array
    , m0 t5 ~, G. s9 Ecellstr        Create cell array of strings from character array
    * A. f0 U3 g/ Umat2cell        Convert array to cell array with potentially different sized cells
    ) n/ K, c: }1 J: Vnum2cell        Convert array to cell array with consistently sized cells7 P. M  f' ~; R
    struct2cell        Convert structure to cell array
    5 A8 b/ Z6 `' f4 E6 v1 r* K测定的数据类型
    ( A9 u% ^( b# b: a3 {* |6 Y/ s
    - z4 c' `$ A9 J( j" U: ^MATLAB 提供各种函数标识数据类型的变量。
    ! J) ~$ F7 b2 _3 ^0 v, m/ n& i, c, X3 t6 A2 `
    下表提供了确定一个变量的数据类型的函数:/ `* K) `( Q8 D' ]; ?( D3 [

    # f7 T9 C4 K& Q( Y; _函数        目的/作用
      z0 W# c7 s( V5 b! t) E+ }is        Detect state
    ' }1 V5 K: p1 d: Fisa        Determine if input is object of specified class) ^, i' r! Q6 N* Z; [& l, _- E0 u
    iscell        Determine whether input is cell array
    * T" H) v$ ?% Q* T# \iscellstr        Determine whether input is cell array of strings
    7 Q7 _- o  E0 a' M4 ~- tischar        Determine whether item is character array
    ( G- o' W  T: [8 sisfield        Determine whether input is structure array field- {! L+ I, h9 ]% f) _, L% }
    isfloat        Determine if input is floating-yiibai array
    ! G/ ?1 g* C& i4 Jishghandle        True for Handle Graphics object handles' c0 }, @3 G8 a3 k% d" m8 a
    isinteger        Determine if input is integer array# f; `, u. Z8 g, n+ K. A
    isjava        Determine if input is Java object  y0 F# X6 \! A& @3 `( K
    islogical        Determine if input is logical array$ u* S0 I4 \9 u  V- a
    isnumeric        Determine if input is numeric array
      O2 h8 T! ?) l/ nisobject        Determine if input is MATLAB object
    - R3 m9 f; _  c1 Z9 y' t8 pisreal        Check if input is real array
    % ?. O( c6 R2 a- N  Qisscalar        Determine whether input is scalar" F3 E$ Y+ j) E7 j1 x8 m! W3 _
    isstr        Determine whether input is character array4 j. M. G2 _+ k/ p. r
    isstruct        Determine whether input is structure array  P( S" T' q. m0 \/ M5 d
    isvector        Determine whether input is vector
    , s7 W  z* g; Oclass        Determine class of object
    - `& J2 f+ M# z) X% ~validateattributes        Check validity of array
    8 c8 B% _7 j4 c/ i) f+ Xwhos        List variables in workspace, with sizes and types" |' _( T9 m( C, p( ]( R- e2 B; h
    例子- E' s4 Y  _- b8 F. b2 T( i

    1 i% J6 W  \- L* G' P: X; A! {+ |创建一个脚本文件,用下面的代码:5 w# A0 r" j" @4 {) [. \( Z
    " E. e. P0 B. p3 S3 q4 U
    x = 3
    2 V* k6 g4 t2 r9 M1 @. lisinteger(x)1 O4 A% _% x. e; I3 w
    isfloat(x)
    ( f# j6 L& v4 U4 Wisvector(x)$ b& G' b; [# }# G
    isscalar(x)7 Q; e. O$ [6 m
    isnumeric(x)$ X& E% l0 M# q+ M5 q7 N2 m

    1 x1 K- t1 b- S' p6 b5 ~; \x = 23.54, |/ H" Z1 w; B8 e4 n; y# L
    isinteger(x)9 H- V8 w  Q* L6 e
    isfloat(x)
    9 x) D- c' P) ~( qisvector(x). s9 u  s: q; v4 ?! x
    isscalar(x)/ x: k4 @. ~4 o, A/ j' w
    isnumeric(x)* V- T7 I* d! H) @0 ^

    - ~0 Y9 i" ]0 U( ]: i4 T. kx = [1 2 3]" N; y* F7 u7 N
    isinteger(x)! M2 G& e; k( S' S5 y- T% {* s
    isfloat(x); }& w# v. V" y  T
    isvector(x)
    0 D6 x# @! j, {7 V# Oisscalar(x)* l& ?8 u6 @; s4 t8 Q

    8 ^$ P1 g% E: H/ V( `) r! Ax = 'Hello'1 {" ~7 D2 A; ?( q2 _$ H) Y
    isinteger(x)6 E$ o6 L- Z& b
    isfloat(x)6 q% ^0 Z$ D0 k/ x9 i8 d7 ]
    isvector(x)
    1 a# [. @0 C: U" kisscalar(x)
    1 i6 \5 [; m, g7 x1 o3 tisnumeric(x)
    # \! K3 }( g9 X' p8 m& f当运行该文件,它会产生以下结果:- \: ~: Z2 x5 S3 `$ k  y+ Q

    - G( U5 Q/ J8 s9 O+ ~x =. }: W- Y0 P7 l; U5 [
         30 |" i* P& U1 g) X! X: ?$ l
    ans =. R( k* N2 B. F- m0 b5 E7 ?
         02 N- a+ |7 H& @  Y! |4 y
    ans =( K6 e' @3 H/ b' Q4 f  ~
         1
    2 r( o  _; j- k  Cans =
    ( V/ J/ O$ F/ b( w     1) k2 c# f7 R- T2 V0 a7 s
    ans =
    5 m( N5 q' P! D! t/ x: `* P     1- Y) {: j) R2 b* K- A6 k
    ans =" k6 L3 L. e6 X4 L
         1
    1 C" t) y; B. W7 J7 L( G+ Ex =
    2 z) c9 z+ w. d6 w% m   23.5400
    / n  C9 X5 M4 eans =
    1 _, I  r) l$ n" W     0
    3 s4 s# `! ]5 H4 l- Xans =& m# M$ A5 f0 d" r. g5 P
         1: B2 x! F2 ^. P+ O# B( M$ s
    ans =
    5 @, n) x  `: a9 G. Q, O+ U% C' N9 V     1
    & b) j1 _: F/ E/ q1 A2 j' ?ans =4 v+ o) H# _: `2 y9 T6 U
         1+ M: v( e' ~6 s7 }
    ans =+ q, `  i, R4 t5 m- B8 N( E2 n
         12 @$ Z, Y+ m2 ~2 w. w
    x =7 g( M  z5 q' Y
         1     2     3
    4 P4 x/ B* n* S& ]) @: eans =! v/ T, x/ c4 ?& _
         0  C) f, G/ M8 t6 ]  k
    ans =. Y/ j- @6 K) J0 h7 h- p
         1! h: F; {9 n  m
    ans =- y9 ], N2 k) x5 `! [) y* p$ J
         1
    ( s, C+ k3 t, r" o/ i5 uans =
    ! q8 G6 m' f, l+ B; o4 F  x( o& H  {     0
    9 ?# |0 z% U$ e3 g! S' t9 ex =
    0 ~" v( H& I5 f; L( J: K( n  gHello) r4 `$ f; W& G- c
    ans =
    1 }" A  y6 w0 |! l  W) l9 m     05 T) c+ {3 c( V/ m
    ans =* h! H9 e! O* T  X, i* h# Q
         0: u7 p9 h) ?; V+ m9 g
    ans =
    : Z  a' s0 z* K" G2 {     1
    3 |; V; J: H. H$ B/ _7 Jans =
    % G- i' z! \8 ^& R% k1 T     0
    8 N5 M" S& W0 x) Oans =# V5 a3 i5 h  b/ N, m
         0
    / c' J) a; \& o- L! v$ J7 T* V* e: \9 J1 }9 E8 Z1 t; I# H8 T
    ————————————————5 _" @3 }8 f  }: I  V# A
    版权声明:本文为CSDN博主「Phil__ming」的原创文章。. G0 y2 E5 X1 U: A. y
    原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575
      g: Q9 r( a- S( v% p# s; p; y1 ^7 x; s5 X# l& E
    , j" `% N6 t6 i5 A2 o/ 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-8-8 03:01 , Processed in 0.443531 second(s), 57 queries .

    回顶部