【问题标题】:Plotting square() and sawtooth() in Octave在 Octave 中绘制 square() 和 sawtooth()
【发布时间】:2015-10-09 16:06:38
【问题描述】:

我试图在 Octave 中绘制方波和锯齿波,但它给出了一个错误提示

>>>error: 'sawtooth' undefined near line 17 column 6
error: 'square' undefined near line 17 column 6
>>>error: 'x1' undefined near line 17 column 21
error: evaluating argument list element number 2
>>>error: 'x2' undefined near line 18 column 21
error: evaluating argument list element number 2

然后我在互联网上阅读,并开始知道我必须安装一些软件包。我安装了必要的软件包以及它们各自的依赖项。尽管这样做了,但这并没有什么不同。同样的错误仍然存​​在。然后我安装了在线存储库中的所有软件包。再次没有任何区别。

我在 Matlab 中运行了相同的代码,它成功了! (我知道它与所有软件包捆绑在一起)。

但我并没有真正理解我在 Octave 中面临的问题。我使用 QtOctave 界面,那里有一个安装包的选项。有什么方法可以检查已安装的软件包吗?他们真的被安装了吗?

我在 FreeMat 中尝试了相同的代码,但也出现了一些错误。

这是我的代码:

% program to plot a saw tooth and square wave
fs = 10000;
t = 0:1/fs:1.5;
x1 = sawtooth(2*pi*50*t);
x2 = square(2*pi*50*t);
subplot(211);plot(t,x1);axis([0 0.2 -1.2 1.2]);
xlabel('Time (sec)');ylabel('Amplitude');title('Sawtooth Periodic Wave');
subplot(212);plot(t,x2);axis([0 0.2 -1.2 1.2]);
xlabel('Time (sec)');ylabel('Amplitude');title('Square Periodic Wave');
set(gcf,'Color',[1 1 1]);

请帮助我让这段代码在 Octave 上工作。

【问题讨论】:

标签: plot octave freemat


【解决方案1】:

为我工作。见https://saturnapi.com/fullstack/plotting-square-and-sawtooth-in-octave

如果您使用的是 Ubuntu,请确保安装必要的软件包

sudo apt-get -q -y install octave-signal

【讨论】:

    【解决方案2】:

    你真的加载了感兴趣的包吗?即使安装了这些包,它们也可能不会加载到您的特定 Octave 会话中。您可以通过在 Octave 提示符处键入 pkg load <package_name> 来执行此操作,将 <package_name> 替换为相应的包名称。

    【讨论】:

    • PS:pkg list 将列出已安装的软件包。加载的包标有* 符号。
    猜你喜欢
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 2014-01-20
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2015-02-17
    相关资源
    最近更新 更多