matlab:introduction_to_matlab
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
matlab:introduction_to_matlab [2017/04/24 03:46] – mithat | matlab:introduction_to_matlab [2021/12/07 19:11] (current) – [Documenting functions] mithat | ||
---|---|---|---|
Line 3: | Line 3: | ||
====== Introduction to MATLAB ====== | ====== Introduction to MATLAB ====== | ||
Mithat Konar\\ | Mithat Konar\\ | ||
- | 2017-04-23 | + | 2019-04-26 |
===== What is it? ===== | ===== What is it? ===== | ||
+ | * A // | ||
* A freaking huge, feature filled graphing calculator | * A freaking huge, feature filled graphing calculator | ||
* Comprehensive | * Comprehensive | ||
Line 33: | Line 34: | ||
===== Variables ===== | ===== Variables ===== | ||
- | * MATLAB has only one numeric type. | + | * Numbers are double precision floats by default. |
- | * Strings | + | * Strings |
* Use single quotes. | * Use single quotes. | ||
* For a literal single quote in a string, use two single quotes. | * For a literal single quote in a string, use two single quotes. | ||
Line 47: | Line 48: | ||
===== Comments ===== | ===== Comments ===== | ||
- | * Use a percent sign. | + | * Use the percent sign. |
<code matlab> | <code matlab> | ||
- | % like this | + | % a single line comment |
a = 99; % this works too | a = 99; % this works too | ||
%{ | %{ | ||
- | foo = 'This is a'; | + | foo = 'multiple line comments'; |
- | baz = 'multiple line comment'; | + | baz = 'use curly brackets inside'; |
+ | qux = 'a pair of percent signs.'; | ||
%} | %} | ||
</ | </ | ||
Line 104: | Line 106: | ||
<code matlab> | <code matlab> | ||
% separate matrix rows with ';' | % separate matrix rows with ';' | ||
+ | |||
a = [1 2 3; 4 5 6; 7 8 9]; | a = [1 2 3; 4 5 6; 7 8 9]; | ||
- | c = [9 8 7; 6 5 4; 3 2 1]; | + | b = [9 8 7; 6 5 4; 3 2 1]; |
</ | </ | ||
Line 111: | Line 114: | ||
<code matlab> | <code matlab> | ||
- | % matrix | + | r = 1.25 * a; % scalar |
- | r = a * b; | + | r = a * b; % matrix |
- | + | r = a .* b; | |
- | % elementwise | + | r = a ./ b; % elementwise division |
- | r = a .* b; | + | |
- | + | ||
- | % elementwise | + | |
- | r = a ./ b; | + | |
</ | </ | ||
Line 265: | Line 264: | ||
</ | </ | ||
- | Una línea: | + | On one line: |
<code matlab> | <code matlab> | ||
while n < 10, y = y * n; n = n + 1; end | while n < 10, y = y * n; n = n + 1; end | ||
Line 277: | Line 276: | ||
</ | </ | ||
- | 一条线 | + | On one line: |
<code matlab> | <code matlab> | ||
for n = 0 : 0.5 : 2, disp(n); end | for n = 0 : 0.5 : 2, disp(n); end | ||
Line 316: | Line 315: | ||
===== With " | ===== With " | ||
* Minimum syntax: | * Minimum syntax: | ||
- | <file matlab | + | <file matlab |
- | function main | + | function main() |
area1 = traparea(1, 2, 3); | area1 = traparea(1, 2, 3); | ||
disp(area1); | disp(area1); | ||
Line 344: | Line 343: | ||
===== Documenting functions ===== | ===== Documenting functions ===== | ||
* First comment block after first line is used to [[https:// | * First comment block after first line is used to [[https:// | ||
- | * What user sees when she types '' | + | * What user sees when they type '' |
* Only with single-function m-files. | * Only with single-function m-files. | ||
<file matlab traparea.m> | <file matlab traparea.m> |
matlab/introduction_to_matlab.1493005590.txt.gz · Last modified: 2017/04/24 03:46 by mithat