diff options
author | James Scott-Brown <james@jamesscottbrown.com> | 2013-09-18 18:05:29 +0100 |
---|---|---|
committer | James Scott-Brown <james@jamesscottbrown.com> | 2013-09-18 18:05:29 +0100 |
commit | 4ddcd660f8d08196c8628156d3e1bc0f1c785d97 (patch) | |
tree | ed385fd1b03955da8f07a7cb07b63129301429c5 /matlab.html.markdown | |
parent | 3eb4dbab9a4a6d9082f424289f982e8489138033 (diff) |
Explain difference between command and function syntax
Diffstat (limited to 'matlab.html.markdown')
-rw-r--r-- | matlab.html.markdown | 17 |
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 |