做项目时老师要求用python,可是书上的列题使用matlab,在matlab完全不会和python只懂一点皮毛的情况下,硬着头皮绘出了第一个图,真的开心,撒花❀❀❀❀
import matplotlib.pyplot as plt
import numpy as np
n=(np.linspace(0,25,125))
g=np.zeros(np.size(n))
for i in range(0,40):
if n[i+1] <= 5:
g[i+1]= 0.5 * (1-np.cos(n[i+1]*np.pi/5))
else:
g[i+1]=np.cos((n[i+1]-5)*np.pi/8)
plt.figure(1)
plt.subplot(121)
plt.plot(n,g)
plt.xlabel('Time/ms')
plt.ylabel('Amplitude')
plt.text(5,0.05,'N1')
plt.text(6,-0.1,'N1+N2')
plt.axis([0,25,-0.4,1.2])
plt.show()
写写几个记得的改错:
1:
g=np.zeros(1,(np.size(n)))
numpy报错 :TypeError: 'numpy.ndarray' object is not callable,改成下面的就行了
g=np.zeros(np.size(n))
2:matlab用()表示矩阵的值,python用[]表示
3: