欢迎来到装配图网! | 帮助中心 装配图网zhuangpeitu.com!
装配图网
ImageVerifierCode 换一换
首页 装配图网 > 资源分类 > PPT文档下载
 

MATLAB课件:ch6 Additional Data Dypes and Plot Types

  • 资源ID:124991800       资源大小:1.26MB        全文页数:49页
  • 资源格式: PPT        下载积分:30积分
快捷下载 游客一键下载
会员登录下载
微信登录下载
三方登录下载: 微信开放平台登录 支付宝登录   QQ登录   微博登录  
二维码
微信扫一扫登录
下载资源需要30积分
邮箱/手机:
温馨提示:
用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
支付方式: 支付宝    微信支付   
验证码:   换一换

 
账号:
密码:
验证码:   换一换
  忘记密码?
    
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

MATLAB课件:ch6 Additional Data Dypes and Plot Types

MATLAB(CH6)Additional Data Dypes and Plot Types2MATLAB(CH6)Complex data String functions Multidimensional arrays Additional data types 2D 3D Plots36.1.1 Complex Variablesc=a+bi =z a=zcos b=zsin 22zab1tanba46.1.1 Complex Variables c=3+4ic=3.0000+4.0000i c=3+4jc=3.0000+4.0000i isreal(c)ans=0 isreal(c)ans=156.1.1 Complex Variables c=2 3;4 5c=2 3 4 5 isreal(c)ans=1 c=2 3;4 5ic=2.0000 3.0000 4.0000 0+5.0000i isreal(c)ans=066.1.2 Using Complex Numbers with Relational Operatorsn,=,c1=4+i*3;c2=3+i*8;c1c2 ans=176.1.2 Using Complex Numbers with Relational Operatorsn=,=Both the real parts and the imaginary parts are compared.c1=4+i*3;c2=4+i*8;c1=c2 ans=086.1.3 Complex Functionsn conj(c)a-bi n real(c)an imag(c)bn isreal(c)n isreal(c)n abs(c)zn angle(c)(radian)c=a+bi =z 9Example(Quadratic Equation)%Calc_roots_2.mdisp(This program solves for the roots of a quadratic);disp(Equation of the form A*x2+B*X+C=0.);a=input(Enter the coefficient A:);b=input(Enter the coefficient B:);c=input(Enter the coefficient C:);10discriminant=b2-4*a*c;x1=(-b+sqrt(discriminant)/(2*a);x2=(-b-sqrt(discriminant)/(2*a);disp(The roots of this equation are:);fprintf(x1=(%f)+i(%f)n,real(x1),imag(x1);fprintf(x2=(%f)+i(%f)n,real(x2),imag(x2);Example(Quadratic Equation)11 Calc_roots_2This program solves for the roots of a quadraticEquation of the form A*x2+B*X+C=0.Enter the coefficient A:1Enter the coefficient B:2Enter the coefficient C:5The roots of this equation are:x1=(-1.000000)+i(2.000000)x2=(-1.000000)+i(-2.000000)Example(Quadratic Equation)126.1.4 Plotting Complex Data0.2()e(cossin)ty ttitPlot the functiont=0:pi/20:4*piy=exp(-0.2*t).*(cos(t)+sin(t)if plot(t,y)is used,only the real data will be plotted!We should use:1.plot(t,real(y);or 2.plot(y);hold on;or 3.polar(angle(y),abs(y);plot(t,imag(y);136.1.4 Plotting Complex Datat=0:pi/20:4*pi;y=exp(-0.2*t).*(cos(t)+i*sin(t);plot(t,y,b-,LineWidth,5.0);title(bfplot of Complex Function vs Time);xlabel(bfitt);ylabel(bfity(t);grid on;14plot(t,y)Only the real data is shown.02468101214-0.6-0.4-0.200.20.40.60.81plot of Complex Function vs Timety(t)156.1.4 Plotting Complex Datat=0:pi/20:4*pi;y=exp(-0.2*t).*(cos(t)+i*sin(t);plot(t,real(y),b-,LineWidth,5.0);hold on;plot(t,imag(y),r-,LineWidth,5.0);title(bfplot of Complex Function vs Time);xlabel(bfitt);ylabel(bfity(t);legend(real part,imaginary part)grid on;16plot(t,real(y);hold on;plot(t,imag(y);02468101214-0.6-0.4-0.200.20.40.60.81plot of Complex Function vs Timety(t)real partimaginary part176.1.4 Plotting Complex Datat=0:pi/20:10*pi;y=exp(-0.2*t).*(cos(t)+i*sin(t);plot(y,b-,LineWidth,5.0);%(It is equal to plot(real(y),imag(y).title(bfPlot of Complex Function);xlabel(bfReal Part);ylabel(bfImaginary Part);axis equalgrid on;18plot(y)-0.500.51-0.4-0.200.20.40.6Plot of Complex Function Real PartImaginary Part196.1.4 Plotting Complex Datat=0:pi/20:10*pi;y=exp(-0.2*t).*(cos(t)+i*sin(t);polar(angle(y),abs(y);title(bfPlot of Complex Function);20polar(angle(y),abs(y)0.2 0.4 0.6 0.8 13021060240902701203001503301800Plot of Complex Function216.2 String Functionse.g.str=Today is Sundaystr=Today is Sunday whos Name Size Bytes Class str 1x15 30 char arrayGrand total is 15 elements using 30 bytes Each character is stored in two bytes of memory.226.2.1 String Conversion Functions x=double(str)x=Columns 1 through 10 84 111 100 97 121 32 105 115 32 83 Columns 11 through 15 117 110 100 97 121 str2=char(x+5)str2=Ytif%nx%Xzsif str3=char(double(str2)-5)str3=Today is Sunday236.2.2 Creating Two-Dimensional Character Arrayse.g.MyUnv=QingDao;University?Error using=vertcatAll rows in the bracketed expression must have the same number of columns.MyUnv=char(QingDao,University)MyUnv=QingDao University246.2.3 Concatenating StringsnFunction strcat concatenates two or more strings horizontally(delete trailing blanks)nFunction strvcat concatenates two or more strings vertically e.g.strcat(Red,Green)ans=RedGreen strvcat(Hello,World)ans=Hello World256.2.4 Comparing Strings 6.2.4.1 Comparing Strings for Equalityn strcmp Determines if two strings are identical;n strcmpi Determines if two strings are identical ignoring case;n strncmp Determines if the first n characters of two strings are identical;n strncmpi Determines if the first n characters of two strings are identical ignoring case;266.2.4 Comparing Strings 6.2.4.1 Comparing Strings for Equality276.2.4.2 Comparing Individual Characters for Equality and Inequalitye.g.a=QingDaoa=QingDao b=huangdaob=huangdao a=b?Error using=eqMatrix dimensions must agree.286.2.4.2 Comparing Individual Characters for Equality and Inequalitye.g.a=QingDao%pad with a blanka=QingDao b=huangdaob=huangdao a=bans=0 0 0 1 1 0 1 1,=,str=hello,worldstr=hello,world isletter(str)ans=Columns 1 through 13 0 1 1 1 1 1 0 0 1 1 1 1 1 isspace(str)ans=Columns 1 through 13 1 0 0 0 0 0 0 1 0 0 0 0 0 306.2.6.5 Number to Stringnstr=num2str(number)nstr=sprintf(format,number)str=num2str(pi)str=3.1416 str=sprintf(The value of pi is%8.6f.,pi)str=The value of pi is 3.141593.316.2.6.6 String to Number nvalue=str2double(str)nvalue=sscanf(str,format)e.g.a=3.1415926 str2double(a)ans=3.1416value1=sscanf(a,%g)value1=3.1416value2=sscanf(a,%d)value2=3 32Other String Functionsn findstrn strmatchn strrepn strtokn uppern lowern int2strn num2strn dec2hexn mat2strn sprintfn sscanf33Other String Functions346.3 Multidimensional Arrays356.3 Multidimensional Arrays c=randn(2,2,3)c(:,:,1)=0.53767 -2.2588 1.8339 0.86217c(:,:,2)=0.31877 -0.43359 -1.3077 0.34262c(:,:,3)=3.5784 -1.3499 2.7694 3.0349 ndims(c)ans=3 size(c)ans=2 2 3366.4 Additional 2-D Plotsx=1 2 3 4 5 6;y=2 6 8 7 8 5;stem(x,y);title(bfExample of a Stem Plot);xlabel(bfitx);ylabel(bfity);axis(0 7 0 10);37Additional 2-D Plots01234567012345678910Example of a Stem Plotxy38Additional 2-D Plotsn bar(x,y)n barth(x,y)n compass(x,y)n pie(x)n pie(x,explode)n stairs(x,y)n stem(x,y)39Additional 2-D Plots40fplotCreate a file,myfun,that returns a two-column matrix:function Y=myfun(x)Y(:,1)=200*sin(x(:)./x(:);Y(:,2)=x(:).2;Create a function handle pointing to myfun:fh=myfun;Plot the function with the statementfplot(fh,-20 20)41-20-15-10-505101520-50050100150200250300350400fplot426.5 3-D Plotst=(0:0.02:2)*pi;x=sin(t);y=cos(t);z=cos(2*t);plot3(x,y,z,b-);43plot3-1-0.8-0.6-0.4-0.200.20.40.60.81-1-0.8-0.6-0.4-0.200.20.40.60.81-1-0.8-0.6-0.4-0.200.20.40.60.81446.5 3-D Plots meshx,y=meshgrid(-4:0.2:4,-4:0.2:4);z=exp(-0.5*(x.2+0.5*y.2);mesh(x,y,z)xlabel(bfx);ylabel(bfy);zlabel(bfz);Use meshgrid to generate a legal 2D dot array before plotting a 3D plot.45mesh-4-2024-4-202400.20.40.60.81xyz46surfx,y=meshgrid(-4:0.2:4,-4:0.2:4);z=exp(-0.5*(x.2+0.5*(x-y).2);surf(x,y,z)xlabel(bfx);ylabel(bfy);zlabel(bfz);47surf-4-2024-4-202400.20.40.60.81xyz48x,y=meshgrid(-4:0.2:4,-4:0.2:4);z=exp(-0.5*(x.2+0.5*(x-y).2);contour(x,y,z)xlabel(bfx);ylabel(bfy);zlabel(bfz);contour49contourxy-4-3-2-101234-4-3-2-101234

注意事项

本文(MATLAB课件:ch6 Additional Data Dypes and Plot Types)为本站会员(努力****83)主动上传,装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知装配图网(点击联系客服),我们立即给予删除!

温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!