10-4 字串?數?????????

int2str OiNƫAഫrơAҦpG

Example 1: 10-rPr/string401.mx = 13462; y = int2str(x) % NƫAഫr length(y) % ˵ y y = 13462 ans = 5

bWҤAܼ x xs@Ӿ 13862Aint2str ONഫ@Ӧr "13462"A׬ 5 ӦrC

YnNରrAi num2str OAҦpG

Example 2: 10-rPr/string402.mstr1 = num2str(pi) % ରrAw]ĦƬO 4 str2 = num2str(pi, 10) % W[pƥHUĦƨ 10 str1 = 3.1416 str2 = 3.141592654

int2str num2str `ΩХܮyIȡAҦpGYnby = sin(x) ϧΤWAХX x = 2.5 yЭȡAiJpUG

Example 3: 10-rPr/string403.mx = 0:0.1:2*pi; y = sin(x); plot(x,y) str = ['\leftarrow (', num2str(2.5), ', ', num2str(sin(2.5)), ')']; text(2.5, sin(2.5), str)

dec2hex OiN 10 iƭȸഫ 16 i쪺rܪkAҦpG

Example 4: 10-rPr/string404.mx = 1026; y = dec2hex(x) y = 402

Ъ`NbWҤAܼ x xsƫAƭȡAܼ y xsƫArCO٦ hex2numBhex2decBdec2hexBbin2decBdec2binB base2dec AХ help Od\UۨϥλykԲӻAbAحzC

mat2str OiNx}ഫrArYAg eval OϥΡAiAܦ^x}AҦpG

Example 5: 10-rPr/string405.mA = [1 2 1; 3 5 6 ]; B = mat2str(A) % Nx} A নr B A2 = eval(B); % ANr B ^x} A2 isequal(A, A2) % A M A2 O_۵ B = [1 2 1;3 5 6] ans = 1

bWҤA mat2str OwN 23 ƭȯx} A ഫAܦGr}C BAMA惡Gr}C B ϥ eval OAͤ@ӻPഫex} A ۦPex} A2C

sprintf OiXƭȩΦrAHͷsrAҦpG

Example 6: 10-rPr/string406.mstr = 'Pv'; newString = sprintf('u%svO %g', str, pi) newString = uPvvO 3.14159

䤤 %s NLXrA%g NLXƭȡAiϥ %f Υ[WLXƤjpƦrAHTͪr榡AԱЬd\ help sprintf C

sscanf i̵w榡ӸѪRXҭnrμƭȡAҦpG

Example 7: 10-rPr/string407.mstr = '2 4.7 5.2'; mat = sscanf(str, '%f') mat = 2.0000 4.7000 5.2000

Hint
sprintf M sscanf ҥΪ榡覡M C y printf M scanf ۷@PC


MATLAB{]pGJg