summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJames Scott-Brown <james@jamesscottbrown.com>2013-09-18 18:05:29 +0100
committerJames Scott-Brown <james@jamesscottbrown.com>2013-09-18 18:05:29 +0100
commit4ddcd660f8d08196c8628156d3e1bc0f1c785d97 (patch)
treeed385fd1b03955da8f07a7cb07b63129301429c5
parent3eb4dbab9a4a6d9082f424289f982e8489138033 (diff)
Explain difference between command and function syntax
-rw-r--r--matlab.html.markdown17
1 files changed, 15 insertions, 2 deletions
diff --git a/matlab.html.markdown b/matlab.html.markdown
index 27b00eba..b8e552e2 100644
--- a/matlab.html.markdown
+++ b/matlab.html.markdown
@@ -37,8 +37,8 @@ clc % Erases the writing on your Command Window
diary % Toggle writing Command Window text to file
ctrl-c % Abort current computation
-edit('myfunction.m') % Open function in editor
-type('myfunction.m') % Print the source of function to Command Window
+edit('myfunction.m') % Open function/script in editor
+type('myfunction.m') % Print the source of function/script to Command Window
profile viewer % Open profiler
@@ -62,6 +62,17 @@ myVariable = 4; % Semi colon suppresses output to the Command Window
a = 2; b = 3;
c = exp(a)*sin(pi/2) % c = 7.3891
+% Calling functions can be done in either of two ways:
+% Standard function syntax:
+load('myFile.mat', 'y')
+% Command syntax:
+load myFile.mat y % no parentheses, and spaces instead of commas
+% Note the lack of quote marks in command form: inputs are always passed as
+% literal text - cannot pass variable values. Also, can't reveive output:
+[V,D] = eig(A) % this has no equivalent in command form
+
+
+
% Logicals
1 > 5 % ans = 0
10 >= 10 % ans = 1
@@ -384,8 +395,10 @@ NaN
inf
% Solving matrix equations (if no solution, returns a least squares solution)
+% The \ and / operators are equivalent to the functions mldivide and mrdivide
x=A\b % Solves Ax=b. Faster and more numerically accurate than using inv(A)*b.
x=b/A % Solves xA=b
+
inv(A) % calculate the inverse matrix
pinv(A) % calculate the pseudo-inverse