mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
cleaned up code, added struct docs
cleaned up code, added struct docs
This commit is contained in:
parent
67de7d7281
commit
759f7349d2
@ -40,18 +40,21 @@ ctrl-c % Abort current computation
|
||||
edit('myfunction.m') % Open function/script in editor
|
||||
type('myfunction.m') % Print the source of function/script to Command Window
|
||||
|
||||
profile on % turns on the code profiler
|
||||
profile of % turns off the code profiler
|
||||
profile viewer % Open profiler
|
||||
|
||||
help command % Displays documentation for command in Command Window
|
||||
doc command % Displays documentation for command in Help Window
|
||||
lookfor command % Searches for a given command
|
||||
lookfor command % Searches for a command in all other commands
|
||||
|
||||
|
||||
% Output formatting
|
||||
format short % 4 decimals in a floating number
|
||||
format long % 15 decimals
|
||||
format bank % only two digits after decimal point - for financial calculations
|
||||
fprintf
|
||||
fprintf('text') % print "text" to the screen
|
||||
disp('text') % print "text" to the screen
|
||||
|
||||
% Variables & Expressions
|
||||
myVariable = 4 % Notice Workspace pane shows newly created variable
|
||||
@ -64,12 +67,13 @@ 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')
|
||||
load('myFile.mat', 'y') % arguments within parantheses, spererated by commas
|
||||
% 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 receive output:
|
||||
[V,D] = eig(A) % this has no equivalent in command form
|
||||
[V,D] = eig(A); % this has no equivalent in command form
|
||||
[~,D] = eig(A); % if you only want D and not V
|
||||
|
||||
|
||||
|
||||
@ -100,6 +104,10 @@ a = {'one', 'two', 'three'}
|
||||
a(1) % ans = 'one' - returns a cell
|
||||
char(a(1)) % ans = one - returns a string
|
||||
|
||||
% Structures
|
||||
A.b = {'one','two'};
|
||||
A.c = [1 2];
|
||||
A.d.e = false;
|
||||
|
||||
% Vectors
|
||||
x = [4 32 53 7 1]
|
||||
@ -160,6 +168,10 @@ A(1,:) % All columns in row 1
|
||||
% 4 5 42
|
||||
% 7 8 9
|
||||
|
||||
% this is the same as
|
||||
vertcat(A,A);
|
||||
|
||||
|
||||
[A , A] % Concatenation of matrices (horizontally)
|
||||
|
||||
%ans =
|
||||
@ -168,6 +180,8 @@ A(1,:) % All columns in row 1
|
||||
% 4 5 42 4 5 42
|
||||
% 7 8 9 7 8 9
|
||||
|
||||
% this is the same as
|
||||
horzcat(A,A);
|
||||
|
||||
|
||||
A(:, [3 1 2]) % Rearrange the columns of original matrix
|
||||
@ -180,10 +194,13 @@ A(:, [3 1 2]) % Rearrange the columns of original matrix
|
||||
size(A) % ans = 3 3
|
||||
|
||||
A(1, :) =[] % Delete the first row of the matrix
|
||||
A(:, 1) =[] % Delete the first column of the matrix
|
||||
|
||||
transpose(A) % Transpose the matrix, which is the same as:
|
||||
A'
|
||||
ctranspose(A) % Hermitian transpose the matrix
|
||||
% (the transpose, followed by taking complex conjugate of each element)
|
||||
transpose(A) % Transpose the matrix, without taking complex conjugate
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user