Matlab_II - Matlab Introduction to Programming Topics...

This preview shows pages 1–9. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Matlab Introduction to Programming Topics covered Use of colon notation If statement Loops For While Creating and Executing Functions Writing data to files Reading data from files Use of Colon notation To create an array from 2 to 5 X = 2 : 5 (Matlab will assign its own increments) To create an array from 2 to 5, with increment of 0.5 Y = 2:0.5:5 Consider a 3 x 3 matrix M = [ 1 2 3; 4 5 6; 7 8 9]; a = (2,:) will assign the 2 nd row to a b = (:,3) will assign the 3 rd column to b If Statement At times, we may need to execute only certain parts of the program We use “if” statement in such situations. The most basic structure for an "if" statement is the following: if (condition statement) ( (program statement(s) ) end The condition statement and program statement(s) are Matlab commands The program statement(s) are executed only if the condition is satisfied If Statement More complicated “if” structures are written as: if (condition statement) (matlab commands) elseif (condition statement) (matlab commands) . . . else (matlab commands) end If Statement The condition statement is a relational or a logical statement Relational operators in Matlab < less than > greater than <= less than or equal >= greater than or equal == equal ~= not equal Note : "=" is used in an assigment statement while "==" is used in a relation Logical operators & and | or ~ not If Statement – An Example % Matlab program illustrating “if” statement clear all; a = 4; b = 4; if (a < b) j = -1; elseif (a > b) j = 2; else j = 3; end To see the value of j, type j and hit Enter! For Loop The "for" loop allows us to repeat certain commands...
View Full Document

{[ snackBarMessage ]}

Page1 / 19

Matlab_II - Matlab Introduction to Programming Topics...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://www.coursehero.com/file/5978835/Matlab-II/", "fetch_time": 1516703817000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2018-05/segments/1516084891886.70/warc/CC-MAIN-20180123091931-20180123111931-00252.warc.gz", "warc_record_offset": 892109388, "warc_record_length": 24708, "token_count": 601, "char_count": 2524, "score": 3.59375, "int_score": 4, "crawl": "CC-MAIN-2018-05", "snapshot_type": "latest", "language": "en", "language_score": 0.8511612415313721, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00062-of-00064.parquet"}