Matlab Learning 01: Array Generation and Trigonometric Function Drawing

Description

Due to the needs of the school curriculum, we have to learn Matlab to complete the digital signal processing experiments. I will organize and publish the relevant knowledge of Matlab after each class.

Array generation

Array generation

1. Colon method

%%生成一个长度为100,从0到99的数组
%%使用:(初值:步长:终值)
%%最后生成:[0,1,...,99]
n = (0:1:99);

2. linspace function

%%生成一个长度为100,从0到99的数组
%%使用:(初值:步长:终值)
%%最后生成:[0,1,...,99]
n = linspace(0,100,1);

In Matlab, the index starts from 1 after the array is generated, not from 0, which needs to be remembered. After the array is generated, get the first element of the array arr through arr(1)

Drawing of trigonometric functions

Take the cosine function cos(x) as an example, use the array generated above to draw the cosine function image (first process the array)

%% 数组生成
x = (0:1:99)*pi/20;
%% cos函数的计算
y = cos(x);
%% 图像绘制
plot(x,y); xlabel('x'); ylabel('y');

The results are as follows
Insert picture description here

Use of subplot

%% 数组生成
x = (0:1:99)*pi/20;
%% cos函数的计算
y = cos(x);
%% 图像绘制,subplot表示绘制图片区域分为两行两列,下一个要绘制的图片处于一号位置
subplot(2,2,1); plot(x,y); xlabel('x'); ylabel('y');

Come here first, continue to update after the next lesson

Guess you like

Origin blog.csdn.net/fuxiaotuo/article/details/109265791