1 / 21

COMP 116: Introduction to Scientific Programming

COMP 116: Introduction to Scientific Programming . Lecture 5 : Plotting, Scripts and publishing. Recap. Matrices and vectors Creating: A=[1:8] B = [ 1 2 3; 4 5 6] Array Indexing x = A(3 ) x = A(1:4). Today. Plotting Scripts Publishing scripts. Very Very useful commands.

hume
Download Presentation

COMP 116: Introduction to Scientific Programming

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. COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing

  2. Recap • Matrices and vectors • Creating: • A=[1:8] • B= [1 2 3; 4 5 6] • Array Indexing • x = A(3) • x = A(1:4)

  3. Today • Plotting • Scripts • Publishing scripts

  4. Very Veryuseful commands • doc <command_name> • Documentation for <command_name> • E.g. >> doc rand • help <command_name> • lookfor <query> • finds commands with matching description

  5. 2D Plotting Basics • The basic line plot • plot(x, y) % plots y vs. x Try >> x = [1:5]; >> y = 2*x; >> plot(x, y);

  6. More on plot plot( x, y, ‘LineSpec’, ‘PropertyName’, ‘PropertyValue’, … ); Try: >> x = linspace(-2,2,100); >> y = x.^3; >> plot( x, y )

  7. Line Specifiers • Line Style: Solid, dashed, dotted, dash-dot • Line Color: Red, green, blue, yellow, … • Marker Style: <None>, Circle, Square, … Try:(dashed red circle) >> x = linspace(-2,2,100);; >> y = x.^3; >> plot( x, y, ‘--ro’ ); >> axis equal;

  8. Explore the following commands • title • xlabel, ylabel • title • legend

  9. Exercise 1 • Plot x vs. sin(x) in the range [0,2*pi] • Solid blue line • Dotted red line • Dashed green line with square markers

  10. Scripts • Create

  11. Write the script • Write the commands

  12. Save to current folder

  13. Run the script • Script should be in the current folder • To run test.m >>test

  14. Comments in scripts

  15. Exercise 1I • Write a script that plots x vs. sin(x) in the range [0,2*pi] • Solid blue line

  16. Publishing • Output your scripts as HTML or Microsoft Word Files

  17. Cells in Scripts • Structure your code using cells http://www.mathworks.com/demos/matlab/developing-code-rapidly-with-cells-matlab-video-tutorial.html

  18. Creating a publishable script • Same as regular script except for the %% command, which acts like a comment, but is also used to separate commands into groups (cells, sections) for publication purposes. Try: %% Publishing Reports - Simple Example %% Area of a Circle % Let us draw a circle in polar coordinates given by % t = 0:0.01:2*pi; % r(t) = t; %% Create Vectors t and r t = linspace( 0, 2*pi, 360 ); r = t; % make r same size as t r(1:end) = 2; % set radius to 2 %% Now plot t vs. r using polar plot polar( t, r, 'ro' ); Remember to save script file as pub_circle.m

  19. Publish Example To publish the script in HTML >> publish( 'pub_circle', 'html' ) Or in MS Word >> publish( 'pub_circle', ‘doc' ) Note: You can also publish from the script Editor window using the File→Publish <scriptname> menu item, defaults to HMTL

  20. Exercise 1II • Write and publish a script that plots x vs. sin(x) in the range [0,2*pi] • Solid blue line • Dotted red line • Dashed green line with square markers • Use cells and comments in the script so that the published report can read and understood by others.

  21. Text Markup for Publishing • Bold Text • Use *<string>* • *comment 1* • Italics • Use _<string>_ • _comment 2_ • Monospacing • Use |<string>| • |comment 3| • Hyperlinked Text • <URL string> • <http://www.google.com Google> • Bulleted Text Items • * Item 1 • * Item 2 • Numbered Items • # Item 1 • # Item 2 Note: You can also use the Editor window to do text markup using the Cell→Insert Text Markup →<???> menu item

More Related