# c9 n q' [* l4 ~5 t数据类型 描述 / O# B3 J1 n5 B; ?4 u- rint8 8-bit signed integer! y" ?4 h9 I% O- d& @
uint8 8-bit unsigned integer 9 P* o6 D. h- p0 Lint16 16-bit signed integer . X& e, I1 t4 U0 z% yuint16 16-bit unsigned integer ! r0 c/ B* o/ H/ ^% n! rint32 32-bit signed integer ; K! b' @3 p- F8 C* r9 ~$ s4 B3 A/ @uint32 32-bit unsigned integer, G3 ~+ B# Z: ?. O- S1 X4 }
int64 64-bit signed integer. n- S1 I$ K: I2 G1 H: E7 y
uint64 64-bit unsigned integer1 k' w. m7 i$ K! s: A/ V
single single precision numerical data- w% I# g7 K- z7 n: w$ d) ~) B
double double precision numerical data6 e1 {9 L1 E; B; S/ }3 p7 n& d$ k
logical logical values of 1 or 0, represent true and false respectively 1 v n4 Q! E+ N! [0 f w- Wchar character data (strings are stored as vector of characters) * @" A8 w. ?! a+ w, k5 X& Hcell array array of indexed cells, each capable of storing an array of a different dimension and data type ; k( {7 m% y5 ?# zstructure C-like structures, each structure having named fields capable of storing an array of a different dimension and data type / ?+ _6 M6 k- M. lfunction handle yiibaier to a function & {5 Z' \8 f" L1 n8 N4 tuser classes objects constructed from a user-defined class 7 q* ^3 F' ~' s: V+ H4 sjava classes objects constructed from a Java class 6 I% G: ~. K6 `' K2 W例子 ) k+ `! `7 q" ~' \ ( n+ k, @; q, E8 n! B& J" r创建一个脚本文件,用下面的代码: $ T N' S7 q o: {* n( `' M, o! N* i- q4 s0 L: p5 N$ d
str = 'Hello World!' 0 i- }9 O; c @n = 23452 }, {! h3 H% [; v& \
d = double(n)$ I) n3 `9 Z1 V0 b @' @
un = uint32(789.50)& g3 h N& o, A8 J+ ]
rn = 5678.92347& _3 z+ `+ ^7 o4 D
c = int32(rn)+ `, W: Q6 b1 O& D6 Y- _
上面的代码编译和执行时,它会产生以下结果: & O9 q) M5 n t, r; f8 ^ ' @! w* U; U9 n, j& Rstr = % O% N+ l1 l; iHello World! 9 N0 Q+ S7 p2 D9 A: k% hn = 3 U: G$ U0 Q2 \- r! x# y! b 2345 + j" ?1 p6 F( w, u2 zd = " q0 e( T! u- d9 }! } 2345: t# N" ]# K8 F
un = & N- M* z$ b/ ~, ~# `/ f% I 790! \! Q$ x2 x' t7 n4 ]- {
rn = " Y8 h9 p+ f3 y2 j7 I* X 5.6789e+03$ l$ R4 x+ _8 V$ W
c = 0 R6 X3 |% S2 T, @; S7 g4 t! a5 N7 L+ Z 5679 7 p* C9 s( ^0 K' b* H+ U数据类型转换 " e# A) O0 b6 y2 A$ |2 H- ]; V* u8 b
MATLAB 提供各种函数,用于从一种数据类型转换到另一种。下表显示的数据类型转换函数:; f; s$ P' _' j; b6 |- F1 B) \
6 l6 k' x. Z: p3 _% t* V+ Q函数 目的/作用 6 ^& d6 E, q* C5 M; @9 Fchar Convert to character array (string) 2 A+ K, \! c" d% ^int2str Convert integer data to string 1 A; i( k8 Y1 Y+ ]mat2str Convert matrix to string : n3 d, x! Q6 p1 A' Nnum2str Convert number to string4 S. k! \# }5 f, ]9 x0 g5 g- t
str2double Convert string to double-precision value 4 A8 }' u2 i$ bstr2num Convert string to number " [* o' P/ X! D# ~# v2 b* j0 T* M7 Unative2unicode Convert numeric bytes to Unicode characters 3 A# V- J9 C6 [/ kunicode2native Convert Unicode characters to numeric bytes7 ~7 L' n. X* G
base2dec Convert base N number string to decimal number # Q$ V9 J: \# F7 F \& D8 gbin2dec Convert binary number string to decimal number5 j) S! O9 `. a3 S
dec2base Convert decimal to base N number in string: Z* H6 t4 s0 t& F- F# e
dec2bin Convert decimal to binary number in string, `* \* N4 G- x
dec2hex Convert decimal to hexadecimal number in string : p$ R. D( X6 D- J1 l/ Mhex2dec Convert hexadecimal number string to decimal number 7 S( Q4 F4 S9 z: u9 ghex2num Convert hexadecimal number string to double-precision number 2 L3 U7 z9 P3 V$ o" ~num2hex Convert singles and doubles to IEEE hexadecimal strings! V5 {; f; f0 M
cell2mat Convert cell array to numeric array ! o( U6 \$ B" H4 ncell2struct Convert cell array to structure array . r9 p0 Z( K3 D( o e* Vcellstr Create cell array of strings from character array+ H" I% I _: v, I. _9 ~% [% F
mat2cell Convert array to cell array with potentially different sized cells2 e0 z- e1 _5 ^
num2cell Convert array to cell array with consistently sized cells 1 ]( v [. `0 V- @9 }struct2cell Convert structure to cell array5 f2 z/ x6 r1 R) P: b
测定的数据类型 " }. ^2 J; G/ J1 t+ B& p $ m$ u; j2 E# ^. Z% b5 S4 DMATLAB 提供各种函数标识数据类型的变量。 ; L9 Q- T( f7 Z3 N: F: @8 a' ~9 w+ y( [; m7 o2 G( w k+ s; ]. o ^
下表提供了确定一个变量的数据类型的函数:( F( s$ o Q- a
. C0 K% h: v4 e9 N* x
函数 目的/作用5 Y6 \2 F0 _$ r! j: Y0 t
is Detect state " Y2 s# G! `" ~% S/ A, V5 visa Determine if input is object of specified class 0 k8 e6 n7 e/ U* `1 a7 W" fiscell Determine whether input is cell array- h/ K/ x' L* F+ n0 R
iscellstr Determine whether input is cell array of strings) C" X6 d6 ]* O4 r
ischar Determine whether item is character array( J8 E5 ]% ]1 Y: x* ~
isfield Determine whether input is structure array field, @7 Y& I+ Y4 ~% o
isfloat Determine if input is floating-yiibai array( \4 `7 f( n. ^4 ?1 f* h. g
ishghandle True for Handle Graphics object handles 4 K7 L2 l) X1 M9 A ` L6 l! iisinteger Determine if input is integer array9 M X$ T9 Y7 F: ]5 H k
isjava Determine if input is Java object : K: X7 x4 ]. ?- Q( p& uislogical Determine if input is logical array8 A3 B1 ^. Y+ O
isnumeric Determine if input is numeric array 3 P' ?" l1 _: ?# Q: jisobject Determine if input is MATLAB object 5 k' f; w/ q, q3 z# o, Y, jisreal Check if input is real array6 v9 `4 N: y% K
isscalar Determine whether input is scalar8 P2 A# U: z w9 \9 J
isstr Determine whether input is character array' f% I2 ]& ~1 ?! ]
isstruct Determine whether input is structure array - }" @, S9 k2 u& I( B3 b1 p1 disvector Determine whether input is vector 8 Y8 P+ z6 L+ C. Nclass Determine class of object, B: z# C% G' t! H: ?" f* q% d
validateattributes Check validity of array( x$ }! U' d6 E. c% p# i: d
whos List variables in workspace, with sizes and types 0 z/ ]/ ]" b' W$ M例子 9 P* s* S' v0 B4 l! {# P 1 y3 s9 D8 S$ @创建一个脚本文件,用下面的代码:! A* o2 G0 D- n7 x. g: f# `" @2 O9 f
/ u9 d, T! L4 V7 N" c" A Tx = 3" T' b9 j+ w. O5 m2 w; Z# _
isinteger(x)* l2 \) |( _) ?% I
isfloat(x) 0 ]5 k: V0 W' t+ f+ X5 b* m. misvector(x) ( \& ]. Q" G: Z) hisscalar(x) $ \( m9 P) j$ t) h' j" L! ~" Kisnumeric(x) ! c6 i- W1 @$ M" c3 f( M0 ^- w- J 0 c: S* U, o9 a/ {x = 23.54/ U, p, `: j$ B
isinteger(x)8 V& j* d9 u7 L- K. E$ |
isfloat(x)2 W$ q9 Q, @5 _. D: x b' U
isvector(x) # A: `1 O ?& ]; `, Misscalar(x) % d2 j' v/ h3 yisnumeric(x)" b$ E+ _) w; x5 \
3 ^8 V3 ?3 ]3 i8 N/ fx = [1 2 3] 8 U% [. y. l- j" I& \ x4 iisinteger(x) 3 C7 C3 {/ Y6 l1 Yisfloat(x)/ X L i/ {5 i( W( ]
isvector(x) $ u: M) ^4 m5 w2 C& Z- N& A/ d, visscalar(x). K$ x5 \1 d7 _, q2 M; d: D
/ S- }1 q5 |& K6 E9 [ m1 f, G
x = 'Hello' , r( M) e$ a4 d: [* j8 a7 @8 Sisinteger(x) ) Z3 K& C1 ^6 d3 h* L9 v- Qisfloat(x) - o* k2 U( u9 F/ _0 Y' W+ u; }isvector(x) ; N8 l o3 _9 e6 L; I! v4 j4 p' S% Visscalar(x)( y$ m8 U. ?7 b- \) t# Z: E
isnumeric(x)6 I; }7 b; F0 G! H% S# L
当运行该文件,它会产生以下结果:2 L: U$ I& b& F: q
, C: a* S" b0 b v8 D* cx =! j0 x+ U4 ]: k4 q: F, R9 L
3 # y' D f7 g5 e" P4 eans =- X6 G R, U9 B p7 b
0 ' z8 m( W1 K7 \! o6 |. \( b: N! i8 Y/ {ans =+ Y) r$ L ~- `- s$ e
1 $ v/ b/ d' @2 |* @; ~+ Zans = ) E/ S& j/ g. R 1! t @& Z/ f3 s/ D$ ^
ans =9 {+ Q2 N+ V/ X. s- ^
1 , @* c0 C+ n* C* pans = : w, C2 A6 X$ Z7 |, v$ e 1$ a6 e. r4 A7 ^; K4 V
x = % u8 A' [1 z) e& D0 h 23.5400 , d$ f! `+ |# d; o$ oans = 3 R9 g' Q/ P7 s% q ] 0 o$ g3 l' Z* \! H# j* }1 p. hans =# z, i9 G% F U
1* L6 z. G& G7 p% {! k. K
ans = `& t/ {+ \/ A+ ?) o7 y
1 & `5 f2 S; Y. w4 l" E! Pans =" J& V5 N) \# d- h
1 , g8 ^& {2 G1 V& p, O6 fans = # w1 e' }2 F5 B1 M6 v! q% { 1 2 s0 V! ~: K! Y0 {4 V& U' ~1 ux =# z% F) r; I9 e# h Q
1 2 3 6 O% u; Q3 _. b) m K+ A& a6 cans = 4 M* H+ [ Z: E \9 _- x 0: p6 c! _! E% O6 I+ u& h
ans =/ i( F6 n x' u% Z
1# H1 u5 x' s0 f
ans = 0 O; n% j' E' U$ C. O; Y3 n1 u" r 1 ' r s1 C9 f$ D; [+ ^/ Dans =* y+ p: W$ D3 N! X# }
0 6 `: \) T3 t+ } S) Y: n/ k6 U/ Vx =7 M1 U7 l# h5 t0 C& }/ e. @& ?
Hello5 @* _! ] k! L; I* [
ans = ; O1 M9 }- S6 [( d/ ] 0" G" O* A# Y; U$ Z0 M$ e; h
ans = 4 E! ^2 i) g4 o: o 0 F" M0 Z0 C5 H! G: m
ans = ; ^2 g3 N$ W2 Z u1 @0 } 1 5 {7 D% J5 |, p0 m( o7 @ans =. ^9 d1 A+ K0 m: U$ ^3 O8 e- `
0 - _2 X( s4 I6 t& t- jans =/ Z/ b! i8 [& Y: s9 l9 r" B
0 0 M5 K9 a( T2 u( G/ D- g' H- v8 |( _! G5 [
————————————————6 a8 o. ? l1 d: ]. K
版权声明:本文为CSDN博主「Phil__ming」的原创文章。; a+ D" m/ ]3 a k* r: z
原文链接:https://blog.csdn.net/Poseidon__ming/article/details/75092575 ) J! z9 i7 q& }, K. ]6 R8 O& C2 e1 G5 a: @1 {2 Q! y @! @
( [# D1 G* T) {0 {, [ 作者: 18019574874 时间: 2020-2-4 15:58
发表回复赞3 W8 [, ], ^5 g