首页 > 解决方案 > 如何将此 MATLAB 代码更改为 python?

问题描述

这是我在 python 中尝试做的 MATLAB 代码 这就是我在 python 上的: import numpy import math

t=numpy.linspace(0,2,16000)

def soundone(t):

  return math.sin(2*math.pi*440*t)

def soundtwo(t):

返回 math.sin*(2*math.pi*880*t)

import matplotlib.pyplot

ax.plot(t, soundone)

ax.plot(t,soundtwo)

plot.show()

我不断收到这些具有不同尺寸的错误,我该如何做到,所以我的情节只显示前 1/100

标签: python

解决方案


soundone并且soundtwo是函数,而不是数组。您需要类似ax.plot(t, soundone(t))或更好的东西soundone = math.sin(2*math.pi*440*t)而不是def积木。

你可以在一行上做情节,ax.plot(t, soundone, t, soundtwo)


推荐阅读