1 / 27

MATLAB 程式設計 Learning Arrays and x-y Plotting

Learn how to create arrays and plot X-Y graphs in MATLAB programming. This tutorial covers topics such as plotting curves, adding labels and titles, and overlaying multiple plots.

Download Presentation

MATLAB 程式設計 Learning Arrays and x-y Plotting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLAB 程式設計Learning Arrays and x-y Plotting 方煒 台大生機系

  2. Ex4_2a xy Plots, Labels, and Titles • dx=.01; • x=.5*dx:dx:10-0.5*dx; • y=sin(5*x); • plot(x,y,’r-’); • xlabel(’\theta’); • ylabel(’F(\theta)’); • title(’F(\theta)=sin(5 \theta)’);

  3. Ex4_2b • dx=.01; • x=.5*dx:dx:10-0.5*dx; • y=sin(5*x); • nhalf=ceil(length(x)/2); • plot(x(1:nhalf),y(1:nhalf),’b-’); • hold on • plot(x(nhalf:end),y(nhalf:end),’k-’); • xlabel(’\theta’); • ylabel(’F(\theta)’); • s=sprintf(’F(\\theta)=sin(%i \\theta)’,5); • title(s);

  4. Ex4_3 Overlaying Plots • dx=.01; x=.5*dx:dx:10-0.5*dx; • y=sin(5*x); y2=cos(x); • % plot both • plot(x,y,'r-',x,y2,'b-') • dx=.01; x=.5*dx:dx:10-0.5*dx; • y=sin(5*x); y2=cos(x); • plot(x,y,’r-’) • hold on • plot(x,y2,’b-’) • Hold off

  5. Ex4_4a xyz Plots: Curves in 3-D Space • clear;close all; • dphi=pi/100; % set the spacing in azimuthal angle • N=30; % set the number of azimuthal trips • phi=0:dphi:N*2*pi; • theta=phi/N/2; % go from north to south once • r=1; % sphere of radius 1 • % convert spherical to Cartesian • x=r*sin(theta).*cos(phi); • y=r*sin(theta).*sin(phi); • z=r*cos(theta); • % plot the spiral • plot3(x,y,z,’b-’) • axis equal N=30 N=10

  6. Ex4_4b • function ex4_4b(N) • close all; • % N is the number of azimuthal trips • dphi=pi/100; % set the spacing in azimuthal angle • phi=0:dphi:N*2*pi; • theta=phi/N/2; % go from north to south once • r=1; % sphere of radius 1 • % convert spherical to Cartesian • x=r*sin(theta).*cos(phi); • y=r*sin(theta).*sin(phi); • z=r*cos(theta); • % plot the spiral • plot3(x,y,z,’b-’) • axis equal; • title(['N= ',int2str(N)]); Ex4_4b(15) Ex4_4b(5)

  7. Ex4_5 Logarithmic Plots • x=0:.1:8; • y=exp(x); • semilogx(x,y); • title(’Semilogx for y=exp(x)’) • pause • semilogy(x,y); • title(’Semilogy for y=exp(x)’) • pause • loglog(x,y); • title(’Loglog for y=exp(x)’)

  8. Ex4_6 Generating Multiple Plots • x=0:.01:20; • f1=sin(x); • f2=cos(x)./(1+x.^2); • figure • plot(x,f1) • figure • plot(x,f2)

  9. Ex4_7 Controlling the Axes • close all; • x=.01:.01:20; • y=cos(x)./x; • plot(x,y); • axis([0 25 -5 5]) • xlim([ 0 20]); • ylim([-5 5]);

  10. Ex4_8 • close all; • x=.01:.01:20; • y=cos(x)./x; • plot(x,y); • axis([0 25 -5 5]); • str1='\alpha \beta \gamma \delta \epsilon \phi '; • str2='\theta \kappa \lambda \mu \nu \pi '; • str3='\rho \sigma \tau \xi \zeta'; • xlabel([str1 str2 str3]); • text(10,1,'\theta_1'); • text(10,2,'\theta_{12}'); • text(10,3,'\theta^{10}');

  11. Ex4_8 Greek Letters, Subscripts, and Superscripts • \alpha \beta \gamma \delta \epsilon \phi • \theta \kappa \lambda \mu \nu \pi • \rho \sigma \tau \xi \zeta • Θ1 is coded with \theta_1 • Θ12 is coded with \theta_{12} • Θ10is coded with \theta ^{10}

More Related