编辑: star薰衣草 2014-10-28
附:

1、命令窗口数据直接输入输出语句(Input) 可利用语句中输入的字符串内容提示用户在命令窗口直接输入程序运行所需的某些参数, 调用格式: R = INPUT('

How many apples'

): 执行后出现提示字符串,输入的内容可以是MATLAB可估值的任何表达式.

输出保存在变量R中. R = INPUT('

What is your name'

,'

s'

): 执行后出现提示字符串,等待字符串输入,字符串直接输出为MATLAB字符串形式. INPUT Prompt for user input. R = INPUT('

How many apples'

) gives the user the prompt in the text string and then waits for input from the keyboard. The input can be any MATLAB expression, which is evaluated, using the variables in the current workspace, and the result returned in R. If the user presses the return key without entering anything, INPUT returns an empty matrix. R = INPUT('

What is your name'

,'

s'

) gives the prompt in the text string and waits for character string input. The typed input is not evaluated;

the characters are simply returned as a MATLAB string. The text string for the prompt may contain one or more '

\n'

. The '

\n'

means skip to the beginning of the next line. This allows the prompt string to span several lines. To output just a '

\'

use '

\\'

. 例:编制可由命令窗口输入被处理温度数据的程序. k=input('

选择转换方式(1--摄氏转换为华氏,2--华氏转换为摄氏):'

);

if k~=1 &

k~=2 disp('

请指定转换方式'

) break end tin=input('

输入待转变的温度(允许输入数组):'

);

if k==1 tout=tin*9/5+32;

摄氏转换为华氏 k1=2;

elseif k==2 tout=(tin-32)*5/9;

华氏转换为摄氏 k1=1;

end str=['

(C'

;

'

(F'

];

disp(['

转换前的温度'

转换后的温度'

]) disp(['

'

,num2str(tin),str(k,num2str(tout),str(k1,:)]) %不同的样条插值函数应用方法: yi=interp1(x,y,xi,'

method'

) yi=method(x,y,xi) 例: 有一正弦衰减数据y=sin(x).*exp(-x/10),其中x=0:pi/5:4*pi,用三次样条法进行插值. 未插值: x0=0:pi/5:4*pi;

y0=sin(x0).*exp(-x0/10);

plot(x0,y0) 方法1:x0=0:pi/5:4*pi;

y0=sin(x0).*exp(-x0/10);

x=0:pi/20:4*pi;

y=spline(x0,y0,x);

plot(x0,y0,'

or'

,x,y,'

b'

) 方法2:x0=0:pi/5:4*pi;

y0=sin(x0).*exp(-x0/10);

x=0:pi/20:4*pi;

y=interp1(x0,y0,x,'

splin'

) plot(x0,y0,'

or'

,x,y,'

b'

)

2、用subplot语句在一个图形窗口上开多个大小不等的子窗口 SUBPLOT('

position'

,[left bottom width height]) 方法:将整个窗口坐标范围视为1*1,每个子窗口可以占用不同比例的局部区域,子区域的界定可用4*1阶矢量[左边坐标,底边坐标,子图宽度,子图高度],各元素均在

0、1间取值. 例:6.7 用subplot语句在一个图形窗口上开多个大小不等的子窗口进行绘图并添加注释,见图. subplot('

position'

,[0.1,0.15,0.3,0.65]) >

>

hist(randn(1,1000),20);

>

>

xlabel('

直方图'

) >

>

subplot('

position'

,[0.45,0.52,0.25,0.28]) >

>

[xp,yp,zp]=peaks;

>

>

contour(xp,yp,zp,15,'

k'

) >

>

hold on >

>

pcolor(xp,yp,zp) >

>

shading interp >

>

hold off >

>

下载(注:源文件不在本站服务器,都将跳转到源网站下载)
备用下载
发帖评论
相关话题
发布一个新话题