[Tutorial] STM32F429 of DSP Chapter 3 Matlab ease of use of the underlying operating

Download the full version of Guide: http://www.armbbs.cn/forum.php?mod=viewthread&tid=94547

Chapter 3 Matlab ease of use of the underlying operating

Matlab tutorial period began to explain the basis of operating ease of use, the essential software as a learning DSP, Matlab master the simple operation is necessary.

3.1 Important Beginners

3.2 Matlab interface description

3.3 Matlab matrix array and

3.4 Matlab retrieved data matrix

Data 3.5 Matlab workspace save and load

3.6 Matlab string

3.7 Matlab function

3.8 Matlab graphics

3.9 summary

 

3.1 Important Beginners

  1.   This chapter introduces the basic operation matlab, if not previously come into contact with this knowledge, it is important to be hands-on operation.

3.2 Matlab interface description

 

  •   The current folder (Current Folder)

It used to access files on your computer.

  •   Command window (Command Window)

For inputting a command, and the like can also be calculated here.

  •   Workspace (Workspace)

Data Browser user-created or imported data from a file.

  •   Command History (Command History)

Record command user command input window, double-click the command history can return to the command window to continue.

The following simple example to explain the use of command window.

3.2.1 simple calculation

In the command window input variable a = 1, then the transport, a re-input, and press Enter.

 

The first input a = 1 and a carriage return will be variable and value added to the workspace (Workspace) in.

After you enter a second time and enter a variable before assignment will be displayed.

3.2.2 slightly more complex computing

In the command window, enter the following calculation:

 

Note: Enter the above line added after the semicolon, the semicolon is very important, with a semicolon and then Enter to enter the next calculation, otherwise it will output the results. When you need to get the results of the settlement, no longer need the semicolon, you can directly enter.

If no, then the variable result, the output is ans = xxx (used as an output variable ans).

3.2.3 command line call history

Call history of the command line you can call in addition to the lower right corner of the Command which can also be achieved through the history of commands query above the keyboard keys ↑ and ↓.

3.3 Matlab matrix array and

Matlab is primarily designed for the entire array and matrix operations. No matter what type of data, all the variables MATLAB is a multidimensional array. Matrix is ​​typically used in a two-dimensional array of linear algebra.

3.3.1 Creating an array

Here create an array of one row and four columns in matlab, each element of the array separated by a comma or space. For example, create an array

 

This type of array is also referred to as a row vector.

Creating a multi-line matrix below, different rows separated by semicolons:

 

Of course, you can also use the built-in Matlab function to create, for example, ones, zeros, rand, etc.

 

And computing a matrix array 3.3.2

MATLAB allows customers to use a single arithmetic or functions to process all the values ​​in the matrix. such as:

 

The following continue to talk about matlab matrix transpose, inverse matrix.

 

  1. Matrix to a symbol plus a 'request for a transposed matrix.
  2. INV () for the inverse matrix.
  3. A matrix is ​​multiplied by the inverse matrix is ​​a demand matrix.

Note that the above results a * inv (a) is no longer obtained integer matrix, Matlab will store the results when stored in the form of a floating point numerical value Matlab actual storage command and the current window display is different. In order to obtain higher accuracy can be displayed using the following data formats

 

Perform multiplication element by element, rather than matrix multiplication can be achieved using the symbol *:

>> a.*a
ans =
     1     4     9
    16    25    36
    49    64   100

Here is the third power of each element of the matrix

>> a.*a
ans =
     1     4     9
    16    25    36
    49    64   100

3.3.3 Matrix consolidation

The combined matrix There are two main forms:

>>A = [a,a]
A =
     1     2     3     1     2     3
     4     5     6     4     5     6
     7     8    10     7     8    10

>>A = [a; a]
A =
     1     2     3
     4     5     6
     7     8    10
     1     2     3
     4     5     6
     7     8    10

 

3.3.4 plural

The complex is represented by the real part and an imaginary part, such as we command window in matlab:

>>sqrt(-1)
ans =
        0 + 1.0000i

To represent the imaginary part of the complex, i or j can be expressed:

>>c = [3+4i,  4+3j,  -i,  10j]
c =
   3.0000 + 4.0000i   4.0000 + 3.0000i   0 - 1.0000i   0 +10.0000i

3.4 Matlab retrieved data matrix

Sometimes more matrix elements for the convenience of the user can retrieve the matrix elements needed to find, call the relevant command. For example: generating a first order magic square matrix with 4 magic function:

>>A = magic(4)
A =
    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1
  •   If we want to obtain data (note that the line began to count from 1) row 4, column 2, the following method can be employed:
>>A(4,2)
ans =
14
  •   Simply, the positioning may be performed using the following methods:
>>A(8)
ans =
    14
  •   If the retrieval range out of the matrix, will be given as follows:
>> test = A(4,5)
Attempted to access A(4,5); index out of bounds because size(A)=[4,4].
  •   Users can add rows and columns by the following method
>> A(5,5) = 14
A =
    16     2     3    13     0
     5    11    10     8     0
     9     7     6    12     0
     4    14    15     1     0
     0     0     0     0    14
  •   Users can access a column of a certain row data by the following method
>> A(1:3,2)
ans =
2
11
7
>> A(3,:)
ans =
     9     7     6    12     0
  •   Colon operator, the user can obtain a sequence of equally spaced, separated by a colon values ​​indicate start: step: end
>> B = 0:10:100
B =
  Columns 1 through 10
     0    10    20    30    40    50    60    70    80    90
  Column 11
      100

If you do not set step, then the output default step is 1.

Data 3.5 Matlab workspace save and load

Workspace variables from the user to create, load or other external data programming added. For example, we enter the following two functions in the command window.

>> A = magic(4);
B = rand(3,5,2);

You can view the contents of the variables in the workspace from the command whos.

>> whos
  Name      Size             Bytes  Class     Attributes
  A         4x4                128  double              
  B         3x5x2              240  double  

Workspace variables are as follows, and the effect of the command whos view is the same.

 

If the user exits Matlab, re-enter the work area, then the inside of the variable data will be cleared. If you want to keep these variations can

Save the following command:

>> save myfile.mat

Next time you open MATLAB can load these variables with the following command:

>>load myfile.mat

In addition users can clear command clears the current workspace variables.

3.6 Matlab string

  •   Display character string is not the same with the use of C, matlab to use single quotes in matlab. such as:
MyText = >> ' the Hello, World ' 
myText = 
the Hello, World

 >> otherText = ' by You ' ' Re right '    % special attention here, the display unit can quote needs to write two. 
otherText = 
by You ' Re right
 
>> whos 
  the Name Size Bytes Class the Attributes 
  myText 1x12                24   char                
  otherText 1x12                24   char   
  •   If you want to combine two strings can use the following method:
>> longText = [myText,' - ',otherText]
longText =
Hello, world - You're right
  •   If you want to convert a string of digital display, or may be a function num2str int2str.
>> f = 71;
c = (f-32)/1.8;
tempText = ['Temperature is ',num2str(c),'C']
tempText =
Temperature is 21.6667C

3.7 Matlab function

MATLAB support function very much, the following cite a simple example, the specific use that function back to consult the manual.

A = >> [ . 1  . 3  . 5 ]; 
B = [ 10  . 6  . 4 ];
 >> max (A)% find the maximum value of 
ANS =
      . 5
 
>> max (A, B)% find A, B of the maximum value of 
ANS =
     10      . 6      . 5
 
>> maxA, = max (A)% maximum value paid maxA, 
maxA, =
      . 5
 
>> [maxA,, LOCATION] = max (A)% maximum value and the next maximum value is assigned to two variables 
maxA, =
      . 5 
LOCATION =
      3
  •   Display any string can call the function:
>> disp('hello armfly')
hello armfly
  •   Clear command window of data can use the command
>>clc

3.8 Matlab graphics

Matlab is very powerful drawing capabilities, the following are brief introduction.

3.8.1 draw lines

The following create a two-dimensional map using the drawing functions:

>> x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)

 

Function by drawing a title to be:

>> x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y);
xlabel('x');
ylabel('sin(x)');
title('Plot of the Sine Function')

 

And you can change the color displayed by the function curve plot (x, y, 'r--').

 

If you want a two waveforms shown in the drawing, the function may be employed hold on, as follows:

>> x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)

hold on

y2 = cos(x);
plot(x,y2,'r:')
legend('sin','cos')

 

3.8.2 3-D drawing

Matlab also supports the 3-D graphics, the following give a simple example to illustrate the main display:

>>  [X,Y] = meshgrid(-2:.2:2);                                
Z = X .* exp(-X.^2 - Y.^2);
surf(X,Y,Z)

 

3.8.3 a plurality of sub-drawing of FIG.

Matlab also supports drawing multiple sub-images in one figure, mainly achieved through function subplot:

>> t = 0:pi/10:2*pi;
[X,Y,Z] = cylinder(4*cos(t));
subplot(2,2,1); mesh(X); title('X');
subplot(2,2,2); mesh(Y); title('Y');
subplot(2,2,3); mesh(Z); title('Z');
subplot(2,2,4); mesh(X,Y,Z); title('X,Y,Z');

 

3.9 summary

In this issue with you on an easy to use Matlab, complicated to use and more behind we need to check the manual, practice more.

Guess you like

Origin www.cnblogs.com/armfly/p/12610976.html