python - 如何将此 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
解决方案
soundone
并且soundtwo
是函数,而不是数组。您需要类似ax.plot(t, soundone(t))
或更好的东西soundone = math.sin(2*math.pi*440*t)
而不是def
积木。
你可以在一行上做情节,ax.plot(t, soundone, t, soundtwo)
推荐阅读
- android - 应用程序没有向用户显示任何可见的崩溃,但 android vitals 仍然给我 Firebase 的崩溃报告
- c++ - 为什么可以从类中的对象访问类的私有变量?
- python-3.x - 无法从 azure devops 安装 mcafee-epo
- javascript - 如何仅使用终端输出vscode打开JS文件时显示的问题列表:?
- command - 在某些情况下,命令是否应该“无所事事”
- reactjs - 环境变量只能在开发过程中访问,如何在部署网站后使其工作?(GatsbyJS 项目)
- java - 为什么类的泛型会影响方法的泛型
- r - R data.table 按组将特定列设置为其最后一个值
- javascript - 使用 PHP 变量作为 Javascript 函数参数
- spring-mvc - 如何在 Sonar 不抱怨的情况下实现 Spring ErrorController?