Перейти к содержимому
Hub Nexus
Все издания

MATLAB Programming

An open textbook from Wikibooks, a chapter a page, in reading order.

42 страницыОбновлено

Начать читать

Подписка — это одно письмо, когда добавляется страница, и ничего, когда страница меняется.

Подписка — это одно письмо, когда добавляется страница, и ничего, когда страница меняется.

Страницы

Страница 1CC BY-SA 4.0
Type this on the MATLAB Command Window My_Var = 10 You will see My_Var = 10 as a response, also note that there would also be an addition to the Base workspace. ![Base Worksapce01]( (Image: ArunMKumar, CC BY-SA 4.0) To check out what all variables are stored in the MATLAB workspace, we can use the f
Страница 2CC BY-SA 4.0
However their number is limited and meaningful names for variables can be created outside this pool of names. To find if any word is a reserved keyword, run this check on the command line. iskeyword('while') The result would be ans = 1 All values of variables are referred by their current instance i
Страница 3CC BY-SA 4.0
Therefore if you have multiple folders and each of them has an M-file of the same name, there will not be a discrepancy if you set the current directory beforehand. The current directory is also the directory in which MATLAB will first look for a data file. If you still want to call a function but i
Страница 4CC BY-SA 4.0
| Equal To | a == b | | --- | --- | | Not Equal To | a ~= b | | Greater than | a > b | | Greater or equal to | a >= b | | Lesser than | a < b | | Lesser or equal to | a <= b | ### Logical Operations Logical Operator is used to check if number fulfills the logical conditions, the result is usually sh
Страница 5CC BY-SA 4.0
% sample script of loading an images >> A = importdata('example1.png'); imread(A) ### Loading Data **load(filename)** can loads data from filename. The files can be text, images , and even audio files. % sample script of loading an audio >> B = load('example2.mp3'); audioread(B,single,1.0) The load
Страница 6CC BY-SA 4.0
Note that MATLAB represents irrational numbers such as pi with rational approximations, except when using the symbolic math toolbox. See that section for details. Boolean numbers are either "TRUE" or "FALSE", represented in MATLAB by a 1 and a 0 respectively. Boolean variables in MATLAB are actually
Страница 7CC BY-SA 4.0
MATLAB Programming, Strings
Страница 8CC BY-SA 4.0
MATLAB Programming, Portable Functions
Страница 9CC BY-SA 4.0
MATLAB Programming, Complex Numbers
Страница 10CC BY-SA 4.0
Let say we have a matrix A as followed: $𝐀 = [ \begin{matrix}1 & 4 \\ 3 & 2\end{matrix} ] .$ To find lambda, we need to know the equation for finding eigenvalue with following formula : $| A − λ I | = 0$ But MATLAB provided a simple way to find eigenvalue using command **"eig"** >> A=[1,4;3,2] A =
Страница 11CC BY-SA 4.0
>> std(V) ans = 6.4807 ### Random Permutation There are two different ways to create random permutations for vector a. **randperm(N)** returns a vector containing a random permutation of the integers 1:N. >> P=randperm(7) ans = 1 6 2 3 4 5 7 b. **randperm(N,K)** returns a row vector containing K uni
Страница 12CC BY-SA 4.0
MATLAB Programming, Vector and Matrices, Operations on Matrices
Страница 13CC BY-SA 4.0
However, we won't be as precise as in mathematics when using the terms vector and matrix. In MATLAB, both are arrays of doubles (thus being a matrix in the real mathematical meaning), and MATLAB considers vectors as a matrices with only one row or only one column. However, there are special function
Страница 14CC BY-SA 4.0
A **vector** in MATLAB is defined as an array which has only one dimension with a size greater than one. For example, the array [1,2,3] counts as a vector. There are several operations you can perform with vectors which don't make a lot of sense with other arrays such as matrices. However, since a v
Страница 15CC BY-SA 4.0
MATLAB is a vector programming language. The most efficient use of MATLAB will involve taking advantage of the built-in capabilities for manipulating data instead of using constructs such as loops. ## Basic Math Most arithmetic operators will work as expected on vectors: >> a = [2 43 943 78]; >> 5 *
Страница 16CC BY-SA 4.0
Note: Structure field names must begin with a letter, and are case-sensitive. The rest of the name may contain letters, numerals, and underscore characters. Use the namelengthmax function to determine the maximum length of a field name. ## Declaring Structures Structures can be declared using the st
Страница 17CC BY-SA 4.0
Cell Arrays can contain differing information in every element. These types of arrays are useful when interacting with spreadsheet software. ## Creating Cell Arrays Cell arrays follow the same conventions as regular arrays except instead of square brackets use curly brackets. array = [1, 2, 3; 4, 5,
Страница 18CC BY-SA 4.0
x1 = [1,2,3,4] y1 = [1,2,3,4] y2 = [4,3,2,1] plot(x1,y1,x1,y2) ### Polar Plot Plots a function using θ and r(θ) t = 0:.01:2*pi; polar(t,sin(2*t).^2) ## 3D Graphics ### plot3 The "plot3" command is very helpful and makes it easy to see three-dimensional images. It follows the same syntax as the "plot
Страница 19CC BY-SA 4.0
MATLAB Programming, Plot
Страница 20CC BY-SA 4.0
As a result this article presents an alternative that requires more lines of code but offers the full formatting flexibility of the generic [plot](/w/index.php?title=MATLAB_Plot&action=edit&redlink=1) command. ## MATLAB's Bode Command The basic bode command is as follows >> bode(LTI_SYS) where - LTI
Страница 21CC BY-SA 4.0
As a result this article presents an alternative that requires more lines of code but offers the full formatting flexibility of the generic [plot](/w/index.php?title=MATLAB_Plot&action=edit&redlink=1) command. ## MATLAB's Nichols Command The basic Nichols command is as follows >> nichols(LTI_SYS) wh
Страница 22CC BY-SA 4.0
As a result this article presents an alternative that requires more lines of code but offers the full formatting flexibility of the generic [plot](/w/index.php?title=Plot_Command&action=edit&redlink=1) command. ## MATLAB's Nyquist Command The basic Nyquist command is as follows >> nyquist(LTI_SYS) w
Страница 23CC BY-SA 4.0
Functions are wholly contained in themselves. They possess their own workspace keeping workspaces separate. This means that all variables necessary for a particular function must be passed or defined in some way. This can get tedious for complex algorithms requiring lots of variables.
Страница 24CC BY-SA 4.0
Select the code you wish to comment or uncomment, and then press Ctrl-R (⌘-/ for Mac) to place one '%' symbol at the beginning of each line and Ctrl-T (⌘-T for Mac) to do the opposite. MATLAB also supports multi-line comments, akin to /* ... */ in languages like C or C++, via the %{ and %} delimiter