Introduction to MATLAB tutorial __matlab

Source: Internet
Author: User
MATLAB Official website: http://cn.mathworks.com/ matlab Chinese forum: https://www.ilovematlab.cn/forum.php

Preparation: Working computer installed MATLAB (you can apply for free trial version in the official website – 30 days) can type

Preface: Because MATLAB is helpful to our work study, so we study it. Presumably to learn the students are on the need for MATLAB, it must be a certain understanding of it, so I will not say more. First Lesson in the Command window, enter the command you want to execute: 1, Array

Input: C=[1 2 3 4;5 6 7 8; 0 9 8 7]
Output:
1 2 3 4
5 6 7 8
0 9 8 7

B[1 2 3 4 5 6 7]
Array does not have 0 bits, c[1]=1
C[4]=4

If the array D

1 2 3 4
5 6 7 8

So d[1]=1 d[2]=5 d[3]=2 d[4]=6 2,disp () command

Disp (' output string ').//Output string Note use single quotes
DISP (C)/output variable

*matlab does not appear dead cycle * 3, there is no semicolon difference

Note that when the code is followed by a semicolon, the run result is not displayed in the Command window when the ENTER key is pressed, or if there is no semicolon, the run result is displayed in the command window. If you need to execute more than one statement at a time, press Shift+enter when you enter the next command. be sure to knock yourself over the example above. Introduction to the second lesson 1,who and whos

Who name
Query command
Whos name Fine

The Who can see some of the variables you've used, whos the variable and the size of the store, and so on. 2,clear Use

Clean and clear all are cleaning up the variables in the workspace
Clear variable name the command is to remove a variable from the difference between 3,size and length

Define string str= ' 12345 '
Size (str)
Will output 1 5
Length (str)
Will output 5
Define string str2= ' 123 456 7 '
Size (STR2)
Output
1 9 (one character per space) 4,SAVE,MKDIR,CD command

save filename variable variable ... The variables of the work space ... Save to Filename.mat file
mkdir C:\Users\Administrator\Documents\MATLAB\Test
The above command is to create a folder named Test under C:\Users\Administrator\Documents\MATLAB.

CD C:\Users\Administrator\Documents\MATLAB\Test into C disk ... Test under this directory
If you have a Haha.mat file under test, enter the command:
CD C:\Users\Administrator\Documents\MATLAB\Test\haha.mat
Output Error Tip:
Error using CD
The directory cannot be changed to C:\Users\Administrator\Documents\MATLAB\haha (Name is nonexistent or not directory a).
You can use Dir to see how many subdirectories are in this directory
then use the CD subdirectory name to enter this subdirectory
Matlab search principle is variable –> function –> file –>matlab and its related thing 5,which use method

which variable name
Returns whether the variable exists
exists return:A is a variable.
Not present: ' B ' not found. (also represents the current directory does not have b this file)

which file name
The file path is returned
Which name first to its variable search element (search to stop), and then function (search to stop), the file (search to stop), MATLAB, other related (search to stop) ... Special variable for 6,matlab (error not searched)

ans Pi inf EPS NaN (not a number means not one data) I J
Because I j is useful in the plural, so we try to avoid using I j when we act as a cyclic section. 7, the operation principle of the variable

1, first define the re operation.
2, variable names are case-sensitive
3, Arbitrary length (only 63 characters accepted)
4, variable legality function isvarname

Variable Type
1. Local variable call finish will eliminate
2. Global variable global variable name defines a global variable
3. Permanent variable after the call will be saved in the workspace (until you exit the MATLAB)

Both 1 and 3 must be defined in the function body
Use the Clear Global command to remove all global variables 8,format format names

Matlab default is short type (four digits after the decimal point)

a=3.5
trial>> format Long//15 digits after decimal point
Trial>> A
A =
3.500000000000000
trial>> format Hex//16 System
Trial>> A
A =
400c000000000000
trial>> format Bank//Two decimal places
Trial>> A
A =
3.50
trial>> format Rat//Rational
Trial>> A
A =
7/2
The command file puts a window instruction into a file is a command file
Matlab
function file input
Complete function only
OutputLesson Three

1.matlab inside is case-sensitive.
Definition c[1 2 3 4]
then enter C (1) which is not able to output 2 of the C array.

2. Index of array 2.1 One-dimensional array

Define one-dimensional array a=[1 2 3 4 5 6]
Ordinal lookup for each element: a (ordinal)
Enter a (1) carriage return
Output 1
Output all arrays: a (:)
can also be a ([1, 2,3, 4])
Output a specific number of elements
A ([1,3,4]) carriage return
Output 1 3 4 2.2 two-dimensional array

Define a two-dimensional array b=[1 2 3 4;5 6 7 8;9 10 11 12]
Find by ordinal: B (serial number)
Enter B (3) Guess what it will output. Output 3. Forget what you said before.
This will output 9

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.