06.08.2013 Views

内容简介作者简介 - 科学与工程计算系

内容简介作者简介 - 科学与工程计算系

内容简介作者简介 - 科学与工程计算系

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.1.3.3 转换函数产生数码字符串<br />

【例 3.1.3.3-1】最常用的数组/字符串转换函数 int2str , num2str , mat2str 示例。<br />

(1)<br />

A=eye(2,4);<br />

A_str1=int2str(A)<br />

A_str1 =<br />

1 0 0 0<br />

0 1 0 0<br />

(2)<br />

rand('state',0)<br />

B=rand(2,4);<br />

B3=num2str(B,3)<br />

B3 =<br />

0.95 0.607 0.891 0.456<br />

0.231 0.486 0.762 0.0185<br />

(3)<br />

B_str=mat2str(B,4)<br />

B_str =<br />

[0.9501 0.6068 0.8913 0.4565;0.2311 0.486 0.7621 0.0185]<br />

Expression=['exp(-',B_str,')'];<br />

eval(Expression)<br />

ans =<br />

0.3867 0.5451 0.4101 0.6335<br />

0.7937 0.6151 0.4667 0.9817<br />

【例 3.1.3.3-2】综合例题:在 MATLAB 计算生成的图形上标出图名和最大值点坐标。<br />

clear<br />

a=2;<br />

w=3;<br />

t=0:0.01:10;<br />

y=exp(-a*t).*sin(w*t);<br />

[y_max,i_max]=max(y);<br />

t_text=['t=',num2str(t(i_max))]; % <br />

y_text=['y=',num2str(y_max)]; % <br />

max_text=char('maximum',t_text,y_text); % <br />

%<br />

tit=['y=exp(-',num2str(a),'t)*sin(',num2str(w),'t)']; %<br />

plot(t,zeros(size(t)),'k')<br />

hold on<br />

plot(t,y,'b')<br />

plot(t(i_max),y_max,'r.','MarkerSize',20)<br />

text(t(i_max)+0.3,y_max+0.05,max_text) % <br />

title(tit),xlabel('t'),ylabel('y'),hold off<br />

4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!