Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.

Similar presentations


Presentation on theme: "COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing."— 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 Very useful commands doc ◦ Documentation for  E.g. >> doc rand help lookfor ◦ 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’, … ); >> x = linspace(-2,2,100); >> y = x.^3; >> plot( x, y ) NameOpt/ReqDescription XOptionalValues on x-axis, default values to 1,2,3,... yValues on y-axis 'LineSpec'OptionalLine specifiers, Default = solid line, no marker, blue color 'PropertyName'OptionalAdditional properties like LineWidth, MarkerSize,... 'PropertyValue'OptionalNumeric values associated with additional properties Try:

7 Line Specifiers Line Style: Solid, dashed, dotted, dash-dot Line Color: Red, green, blue, yellow, … Marker Style:, 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/developi ng-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 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 * * ◦*comment 1* Italics ◦ Use _ _ ◦_comment 2_ Monospacing ◦ Use | | ◦|comment 3| Hyperlinked Text ◦ 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


Download ppt "COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing."

Similar presentations


Ads by Google