' y. O+ i7 F2 ]" T/ O数据类型 描述 9 x0 q- p* A/ T. x) Sint8 8-bit signed integer8 K4 d2 m# t. i* Q" s
uint8 8-bit unsigned integer9 D% O4 K& m3 Z1 G
int16 16-bit signed integer ; w0 P) K5 C) }$ u1 Luint16 16-bit unsigned integer ( R7 P& j9 c/ c, [( W, Bint32 32-bit signed integer + K1 M2 z4 j$ B- t! suint32 32-bit unsigned integer / c# I) [$ N$ U" z/ J. Nint64 64-bit signed integer% m1 ?9 U& n' t2 Q( R0 \
uint64 64-bit unsigned integer6 y* M, h9 }' j# q6 b3 o0 r. r* @, I
single single precision numerical data , d2 T, z* s& ^% e$ r9 B8 o' pdouble double precision numerical data2 r* s) ~9 U. `3 r( d
logical logical values of 1 or 0, represent true and false respectively , [2 }( L. E" C, Y! o8 ^char character data (strings are stored as vector of characters)1 ^' j" T4 N$ o/ w- f
cell array array of indexed cells, each capable of storing an array of a different dimension and data type , s0 y5 g+ F' d; M! v. { Gstructure C-like structures, each structure having named fields capable of storing an array of a different dimension and data type' C/ B7 E" N0 n1 R: H% e
function handle yiibaier to a function " q" j, p& ?6 wuser classes objects constructed from a user-defined class- l# `* @1 A+ `* W2 E$ a
java classes objects constructed from a Java class + p+ C* n' N" v! s例子+ [) b3 N0 h7 j5 t$ R
$ w2 y( |' K$ ]7 M d9 O$ _1 s
创建一个脚本文件,用下面的代码: * M8 S: w1 f) t. y8 k& a0 J4 A B' @% y/ u4 C
str = 'Hello World!'0 K Y2 `5 s, B. C( n; Y$ U
n = 2345 & f* v/ J* {" W: cd = double(n). J+ k y, Y" j
un = uint32(789.50)5 D% v4 p' v7 z E% W: H8 \" I
rn = 5678.92347- k9 L" `/ @! l6 h% A& s
c = int32(rn), X# t0 ~5 j( I1 q! i) s
上面的代码编译和执行时,它会产生以下结果:& M0 [$ N9 c9 P- M5 u: z/ `/ n0 q
: d; i0 i8 a2 w% z7 v) V) E# wstr =4 u- X1 A: Z$ g* \7 W8 T5 G( t
Hello World!, r6 v9 i% r- ]9 n& ~7 o+ }
n =1 i0 j4 E& o3 p0 a! y) U
2345 ) v7 G" k( O; v& A# kd =7 _) V2 Z$ O5 ?' g3 u
23459 l- i: Y6 C) X) m7 ]
un =; ]& r# [8 f1 g7 }. `
7902 c: W9 Q* u7 ?8 U% m2 E- Y2 X* M; s
rn = 7 O i; p8 a6 D K$ L 5.6789e+03. Y1 I4 h; A- j) ?: X
c = 8 v2 l) X9 }# u. ] 5679 8 D) V% _$ @2 a; N数据类型转换# C% h. K, ?+ W
, y7 F, s4 n: ~5 i0 o AMATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数: 1 X7 O3 @8 L2 z+ P# f: F. G% j/ s; C" ~+ J) O# O
函数 目的/作用# L5 h0 O5 M. K. R% r" t
char Convert to character array (string)7 V% `0 l1 b: t( L/ \
int2str Convert integer data to string5 o! O# W7 p! @. j' X. S' k$ J$ J8 ]
mat2str Convert matrix to string - q6 l: [/ a& `: }) Ynum2str Convert number to string% h4 d+ q, a5 Z7 e
str2double Convert string to double-precision value( u |2 T9 @+ B6 k7 R0 M' N
str2num Convert string to number' g: e! o" g: _8 j3 m9 ?
native2unicode Convert numeric bytes to Unicode characters6 O3 }0 ~8 {4 `5 S
unicode2native Convert Unicode characters to numeric bytes3 u6 _4 @3 X( t: E, w4 }; X
base2dec Convert base N number string to decimal number- s$ I9 P. P8 H1 z
bin2dec Convert binary number string to decimal number # z& C. B2 V: b. @dec2base Convert decimal to base N number in string& f# r# D. n8 s; n/ n3 ~
dec2bin Convert decimal to binary number in string + A1 r! S1 x6 gdec2hex Convert decimal to hexadecimal number in string 3 p' E" L) h5 @5 |hex2dec Convert hexadecimal number string to decimal number6 x# q, l- Q% v, V* Q4 u
hex2num Convert hexadecimal number string to double-precision number & K, D4 j0 e- M( l2 K5 qnum2hex Convert singles and doubles to IEEE hexadecimal strings0 a* z9 o- M* p
cell2mat Convert cell array to numeric array# q% p# y, L% z' {5 g, S/ p& b
cell2struct Convert cell array to structure array: s f& P0 ?* [4 p
cellstr Create cell array of strings from character array 7 l0 O$ p& ~8 z Z3 Ymat2cell Convert array to cell array with potentially different sized cells 8 ?- p: ]' M2 N1 X6 lnum2cell Convert array to cell array with consistently sized cells 0 m( w, f6 i* Q/ @$ Pstruct2cell Convert structure to cell array 1 n2 Z/ h/ |/ ~: r d9 ^- R测定的数据类型 H- s- [, ]* N k& }, X, @8 }; I" g, B
" C3 F, [4 I. G, U
MATLAB 提供各种函数标识数据类型的变量。1 O1 h5 V% H+ F% c K3 Y
9 S. y! ~* V% I, {. m下表提供了确定一个变量的数据类型的函数: 1 y- b+ S) I2 A6 p& [9 c8 \+ g- ~# _
函数 目的/作用 - [6 f' z/ r2 h/ j. Q3 Ais Detect state 4 Z9 Y6 b5 U* m n* Cisa Determine if input is object of specified class5 \+ X& U2 T1 h) o: W
iscell Determine whether input is cell array ; B: ?5 q9 I/ z! e1 A9 @- q7 V0 ~iscellstr Determine whether input is cell array of strings! q) c2 _$ R' s) I
ischar Determine whether item is character array, x( }5 ]' f+ D8 `2 t1 r3 o
isfield Determine whether input is structure array field6 J, |# l- M7 Y' h) [4 L7 N( h/ C
isfloat Determine if input is floating-yiibai array8 F: k+ u, ?' U
ishghandle True for Handle Graphics object handles * G& @' e3 A/ E% t5 I: g Sisinteger Determine if input is integer array! d6 ^7 y* z9 y
isjava Determine if input is Java object, ~7 x6 V6 r N
islogical Determine if input is logical array / T9 c) @7 ]3 g- O6 `3 ~) Y' e5 Eisnumeric Determine if input is numeric array + y. ]5 R3 x0 R# M. m: v$ tisobject Determine if input is MATLAB object ; m7 i# c0 f$ V2 @4 u3 t+ a) kisreal Check if input is real array5 G4 w; w9 ]5 e% b/ u2 M9 G! Y
isscalar Determine whether input is scalar& N+ Q2 m0 Y5 }* h0 s
isstr Determine whether input is character array ) @- I1 ^0 h; k% j7 |isstruct Determine whether input is structure array/ D5 _: L" X8 L1 a: S' b% O' [- ~
isvector Determine whether input is vector & \) s# _- S+ iclass Determine class of object2 E" S s0 J8 J+ K' F0 p
validateattributes Check validity of array1 h: `+ ?7 v. X
whos List variables in workspace, with sizes and types $ |3 x0 D+ n- n" b, P例子 2 Z1 Q6 D3 `1 h% _9 S o H7 ? & ]% w* R, u) a( F% O7 Z创建一个脚本文件,用下面的代码:) y' l8 \, r2 H9 h% }3 M( I
5 R( Z9 a2 T, H3 Z
x = 3 ! ^+ S: Z }' Lisinteger(x)0 f9 j! }5 N a( U+ R
isfloat(x)0 a" n3 ^$ d$ ^! w" z2 \( i3 Q6 s+ j
isvector(x)8 F- v! o% F$ c+ h. B
isscalar(x) 8 w f( p0 z$ J# V/ Misnumeric(x) " v" ^: ^, r' U9 {4 r+ t" T9 i ! n# S; ^% I) |! X5 V' y$ ^x = 23.54+ t( o4 z7 f$ E* k8 g6 z3 p
isinteger(x) 3 b' w% ~3 b' c; B# K! wisfloat(x)5 i h( j6 D$ i2 h/ X. u- ]
isvector(x): s9 k+ @' A. C$ K# a
isscalar(x)& R/ p$ p! _6 b2 X
isnumeric(x)8 b' K M( D) v" ^* I3 \ S
( W2 w9 e$ O% ux = [1 2 3] $ o5 q7 ~; K3 ?, z; @+ p. jisinteger(x) 8 D) v3 K* V$ g# ]4 _$ Zisfloat(x)8 s$ ~/ n+ N' m( a/ J9 w6 ]4 \7 h
isvector(x). l. g( E r$ d0 g+ y
isscalar(x)& j" }8 _$ u2 P" m7 f* @) l r
& j$ W* E k- K7 R3 \
x = 'Hello'# L% I9 @* z$ x7 {7 Y% @) W
isinteger(x) + V5 L: I2 B! ~' Y8 Fisfloat(x) 1 s7 a: ^5 u: }5 ~' j% ]+ gisvector(x) 6 g+ n8 K" u V3 [& P/ l/ {isscalar(x) , ~- O$ M: x/ h5 uisnumeric(x) ) F" G# k+ v6 I9 ~7 a1 T- X当运行该文件,它会产生以下结果: 0 H; C; b: h, O* P/ }/ f" P4 a - ~7 m. N, f4 r* v4 qx = * u, r. U4 f* p) U" k& U4 q% q 3 # E! {2 t8 B4 A! x# z( ^ans =) k r% O, o* n$ b( e
0 2 ~1 l, D. b9 r, q$ Pans = # d& r; Q: F: _) B! Z3 X 1 % ?, l* u ^! l- K$ X+ Z' q5 dans = # l/ z. A [7 o X: f$ m 1( M3 d9 }5 R+ D s+ _% t
ans = . m( Q( p7 a2 M( d+ F% ] 1 ; g D- Z0 L0 Z8 I3 lans =) q/ A+ M1 h( a8 l; B. a9 Q
1 0 u( Q+ `# `6 ^0 X7 h8 y( g( sx = 5 r" X, v+ \( W" I9 X 23.5400 + D7 u4 \5 @9 f. K8 u4 Pans =: Y- U" x8 c2 p6 f( H
05 c( F) O! m9 ~" t
ans =) q$ M4 E; P/ S
1 6 G+ F3 B1 N* i) I2 U2 t7 Kans = 5 `8 A: l2 S% E) r 1! o2 m; \1 c8 K" z- {. m4 M% i: p
ans = / N% f1 c( r0 F5 j3 B1 s( K 1 . `- j( O- n! A& d# R, S4 `$ _& dans = 0 @( | R+ k/ H0 x 1 1 M6 a6 ?. @2 ?5 p* Rx = $ ~# L w! m" E" X, c! W! y 1 2 3 * {! O1 D2 i* P" T; c" {ans = - I" G7 B1 o/ i& A8 }5 S 06 z% l1 t* e' b( X. s/ C
ans =" i" r* J% H4 ^
1/ M G5 e; X: U" P, x/ }
ans = 0 y5 U; V$ w) i4 y( l [. w 1 3 X) K9 \, x$ u6 I5 k/ Oans =; x0 J5 N+ o, `" |' k
0 : D( K8 ~5 r9 G0 m7 Vx =8 A4 E6 Z$ O+ E; }+ ?2 y1 Y/ T
Hello 4 R9 t0 N% `) n& c. F9 O; [ans = $ z) N4 N; G5 t: p9 O 0 ) t' }( o- |$ j9 D1 j2 D- y, wans = K- d: k8 D0 ~( Z 0 : A1 f9 I* Q' Uans =0 f9 @& b/ Q0 {# I0 Y, @
14 Q' @' X A8 o; g5 _9 N; c& N
ans = / ~3 ^! j/ _7 ?3 K 0 6 d8 N) x- N+ b) P( h# _ans = $ M* F6 ?1 s2 A- _ C2 ?& m1 x 0 + s" z: g8 w- [8 o% R% O5 B, i7 c! W+ O: i) s
————————————————7 Y* g& \2 K1 d
版权声明:本文为CSDN博主「Phil__ming」的原创文章。0 }8 u1 @ {7 U- Z* F
原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575 * K5 A9 b: ~# d' g5 b8 ]4 `( ?- d: O