1 / 19

COMP 116: Introduction to Scientific Programming

COMP 116: Introduction to Scientific Programming . Lecture 6: Scripts and publishing, Creating matrices. Recap. Very Very useful commands doc < command_name > e .g. >> doc rand help < command_name > lookfor <query> C reating arrays x= linspace (0,2*pi,100); Plotting

pink
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 6: Scripts and publishing, Creating matrices

  2. Recap • Very Very useful commands • doc <command_name> • e.g. >> doc rand • help <command_name> • lookfor <query> • Creating arrays • x=linspace(0,2*pi,100); • Plotting • >>plot(x, sin(x), ’:r’) • >>plot(x, sin(x) ’-og’)

  3. Scripts • Create

  4. Write the script • Write the commands

  5. Save to current folder

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

  7. Comments in scripts

  8. Exercise 1 • Write a script that plots a square with dotted red edges/lines

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

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

  11. Creating a publishable script %% Sine curves: The ups and downs of life; %% Create Data x=linspace(0,2*pi,100); y=sin(x); %% Now plot x vs. y: The Basic solid blue plot plot( x, y); %% The dotted red line plot(x,y,’:r’); %% Green line with green squares plot(x,y,’sg’); • 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.

  12. 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

  13. Exercise 1I • Write and publish a script that plots • A triangle with solid blue lines/edges • A square with dotted red lines/edges • Use cells and comments in the script so that the published report can be read and understood by others.

  14. 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

  15. Matrices • Each element of the matrix is a variable(memory location) • To create this 3x4 matrix • y=[3 4 8 41; 35 7 22 11; 8 11 27 2] • An array is a 1xn matrix

  16. Matrix operations • m=[3 6 4; 1 2 3] • Matrix-Scalar operations >>m=m*2 >>n=m-3 • Matrix-matrix operations (must be same size) >>p=m+n >>q=m.*n (use . for multiplication and division)

  17. Creating matrices >>rand(m,n) mxn matrix of random numbers >>zeros(m,n) all zeros >>ones(m,n) all ones >>eye(m,n) identity matrix >>diag(v) diagonal matrix >>doc <command_name> to get detailed documentation e.g. >>doc diag

  18. Matrix indexing • m=[3 6 4 5; 1 2 3 9; 11 2 1 9] • Individual elements • m(2,3) • m(2,1)=7 • Rows • m(2,:)=[7 1 6 4] • m(3,:) • Columns • m(:,2) • m(:,3)=[1; 9; 7] • Block • m(2:3,2:end)

  19. Assignment 1 • Images as matrices

More Related