mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Explain difference between command and function syntax
This commit is contained in:
parent
3eb4dbab9a
commit
4ddcd660f8
@ -37,8 +37,8 @@ clc % Erases the writing on your Command Window
|
|||||||
diary % Toggle writing Command Window text to file
|
diary % Toggle writing Command Window text to file
|
||||||
ctrl-c % Abort current computation
|
ctrl-c % Abort current computation
|
||||||
|
|
||||||
edit('myfunction.m') % Open function in editor
|
edit('myfunction.m') % Open function/script in editor
|
||||||
type('myfunction.m') % Print the source of function to Command Window
|
type('myfunction.m') % Print the source of function/script to Command Window
|
||||||
|
|
||||||
profile viewer % Open profiler
|
profile viewer % Open profiler
|
||||||
|
|
||||||
@ -62,6 +62,17 @@ myVariable = 4; % Semi colon suppresses output to the Command Window
|
|||||||
a = 2; b = 3;
|
a = 2; b = 3;
|
||||||
c = exp(a)*sin(pi/2) % c = 7.3891
|
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
|
% Logicals
|
||||||
1 > 5 % ans = 0
|
1 > 5 % ans = 0
|
||||||
10 >= 10 % ans = 1
|
10 >= 10 % ans = 1
|
||||||
@ -384,8 +395,10 @@ NaN
|
|||||||
inf
|
inf
|
||||||
|
|
||||||
% Solving matrix equations (if no solution, returns a least squares solution)
|
% 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=A\b % Solves Ax=b. Faster and more numerically accurate than using inv(A)*b.
|
||||||
x=b/A % Solves xA=b
|
x=b/A % Solves xA=b
|
||||||
|
|
||||||
inv(A) % calculate the inverse matrix
|
inv(A) % calculate the inverse matrix
|
||||||
pinv(A) % calculate the pseudo-inverse
|
pinv(A) % calculate the pseudo-inverse
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user