当前位置:网站首页>Summary of MATLAB basic grammar
Summary of MATLAB basic grammar
2022-07-25 00:37:00 【Brave NN】
1. Interface understanding
- Command line input clc: Clear the command line window
- Command line input clear all: Clear the right workspace
- %: Comment code
2. Variable naming
- Case sensitive
- Start with a letter , You can use underscores
3. data type
- Numbers :abs()
- Characters and strings : String in single quotes 、char()、length()
- matrix
A=[1 2 3; 4 5 6; 7 8 9]
B=A' % Transposition
C=A(:) % Vertical stretching
D=inv(A) % Seeking inverse
A*D
E=zeros(10,5,3) % 10 That's ok 5 Column 3 dimension
E1=rand(10,5) % 0-1 A pseudo-random number uniformly distributed between
E2=randi([3,7],10,5) % A fixed range of random integers
E3=randn(10,5) % Pseudorandom number of standard normal distribution ( The mean for 0, The variance of 1)
- Cell array
A=cell(1,6) % 1 That's ok 6 A cellular array of columns
A{
2}=eye(3) % 3 That's ok 3 Unit matrix of columns
A{
5}=magic(4) % 4 Step magic square
- Structure
books=struct('name',{
{
'Machine Learning','Data Mining'}},'price',[30,40])
books.name
books.name(1) % 1×1cell
books.name{
1} % character string
4. Matrix construction and four operations
- Matrix construction
A=[1 2 3 4 5 6]
B=1:2:9 % The scope is 1-9, In steps of 2
C=repmat(B,3,2) % Give Way B Matrix repetition 3×2 Time
D=ones(4,4) % Generate 1 individual 4×4 Of all the 1 matrix
application :
Solve a system of linear equations :
A=[5 6 -12; 6 5 -2; 4 -9 2;]
B=[1 129 17]'
invA=inv(A)
X=invA*B
- arithmetic
A=[1 2 3 4; 5 6 7 8]
B=[4 3 2 1; 8 7 6 5]
C=A+B
D=A-B
E=A*B' % matrix multiplication ,A The line of =B The column of
F=A.*B % Multiply the corresponding terms
G=A/B % G*B=A
H=A./B % The corresponding term is divided by
- The subscript of a matrix
A=magic(5)
B=A(2,3) % take A Matrix No 2 Xing di 3 Number of columns
C=A(3,:) % take A The order of the matrix 3 That's ok
D=A(:,4) % take A The order of the matrix 4 Column
[m,n]=find(A>15) % find A Greater than in matrix 15 Number of numbers , And expressed by subscript
5. Program structure
- for
% seek 1-5 The sum of the squares
sum=0;
for i=1:5
sum=sum+i^2;
end
- if
a=100;
b=20;
if a>b
' establish '
else
' Don't set up '
end
- while
% seek 1-10 And
sum=0;
n=1;
while n<=10
sum=sum+n;
n=n+1;
end
6. 2D plane drawing
Example 1:
x=0:0.01:2*pi;
y=sin(x);
figure % Curtain
plot(x,y)
title('y=sin(x)')
xlabel('x')
ylabel('sin(x)')
xlim([0 2*pi])

Example 2:
x=linspace(0,30,500); % 0-30 Between 500 Elements
y=x.*sin(x); % Gain sine function
plot(x,y,'LineWidth',1.5); % The line width is 1.5
title(' Gain sine function ');
xlabel('\alpha');
ylabel('sin(\alpha)');
legend('sin(\alpha)'); % Insert line callout
text(2,2*sin(2),'\rightarrow Okey!'); % Insert text and arrows
grid on; % Show gridlines
box on; % Show axis box

Example 3:
x1=linspace(0,2*pi,100);
x2=linspace(0,3,100);
y1=1/3*x1.*sin(2*x1);
y2=x2.^2+2*x2;
plot(x1,y1,'r:',x2,y2,'b--');

Example 4:
x=linspace(0,2*pi,60);
subplot(2,2,1);
plot(x,sin(x)-1);
title('sin(x)-1');
axis([0,2*pi,-2,0]);
subplot(2,1,2);
plot(x,cos(x)+1);
title('cos(x)+1');
axis([0,2*pi,0,2]);
subplot(4,4,3);
plot(x,tan(x));
title('tan(x)');
axis([0,2*pi,-40,40]);
subplot(4,4,8);
plot(x,cot(x));
title('cot(x)');
axis([0,2*pi,-35,35]);

7. Three dimensional drawing
Example 1:
x=0:pi/50:10*pi;
plot3(sin(x),cos(x),x);
xlabel('sin(x)');
ylabel('cos(x)');
zlabel('t');
grid on;
axis square; % Set the current coordinate system drawing to square

Example 2:
[x,y,z]=peaks(30);
mesh(x,y,z);
grid on;

边栏推荐
- Codeworks round 649 (Div. 2) ABC problem solution
- C language force buckle the flipped number of question 7. Violence Act
- [LeetCode周赛复盘] 第 83 场双周赛20220723
- Leetcode 0125. validate palindrome string
- Multi table query of SQL
- Verification of Kirchhoff's law and Multisim Simulation (engineering documents attached)
- Why do I have to clean up data?
- Redis 事务学习有感
- Mobile terminal touch event
- Two numbers that appear only once in the array
猜你喜欢
![[Bert] transformer/bert/attention interview questions and answers](/img/32/5d29ce8056df16211630c3384adcf4.png)
[Bert] transformer/bert/attention interview questions and answers

Improve static loading dynamic loading

Redis6.2 SYSTEMd startup prompt redis service: Failed with result ‘protocol‘.

3. Pressure test

动态规划-01背包滚动数组优化

Fast development board for Godson solid state drive startup (burning system to solid state) - partition

Dpdk based basic knowledge sorting-01
![[mindspore ascend] [running error] graph_ In mode, run the network to report an error](/img/81/9e96182be149aef221bccb63e1ce96.jpg)
[mindspore ascend] [running error] graph_ In mode, run the network to report an error

UART

The new version of Alibaba Seata finally solves the idempotence, suspension and empty rollback problems of TCC mode
随机推荐
2022 Henan Mengxin League game 2: Henan University of technology K - Rice
Codeworks round 650 (Div. 3) ABCD solution
Ggplot2 visual faceting, visual faceted ridge plot with facet_wrap, and customize the background color of the faceted icon title box
Netease game Flink SQL platform practice
Nodejs package
Oracle is not null cannot filter null values
BGP机房和BGP
Add the two numbers in the linked list of the second question of C language. Ergodic method
Measurement and Multisim Simulation of volt ampere characteristics of circuit components (engineering documents attached)
ROS manipulator movelt learning notes 3 | kinect360 camera (V1) related configuration
494. Target sum · depth first search · knapsack problem
LeetCode_6124_第一个出现两次的字母
jquer $(‘div li‘) $(‘div,li‘) $(‘div>li‘) $(‘div‘,‘li‘)
Promtool Check
If real-time intersection with line segments in online CAD drawings is realized
NFT chain game system development metauniverse gamefi construction
2. Load test
Server intranet and Extranet
asp adodb.stream对象的方法属性
Principle of data proxy