简体   繁体   English

在Octave中绘制square()和sawtooth()

[英]Plotting square() and sawtooth() in Octave

I was trying to plot a square wave and a saw-tooth wave in Octave, but it gave an error saying 我试图在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

Then I read up on internet, and came to know that I have to install some packages. 然后我在互联网上阅读,并且知道我必须安装一些软件包。 I installed the necessary packages and also their respective dependencies. 我安装了必要的包以及它们各自的依赖项。 In spite of doing that, it did not make a difference. 尽管如此,它并没有什么不同。 The same error persisted. 同样的错误仍然存​​在。 I then installed all the packages from the online repositories. 然后我安装了在线存储库中的所有软件包。 Again that made no difference. 再一次没有区别。

I ran the same code in Matlab and it worked! 我在Matlab中运行相同的代码并且它有效! (I know it comes bundled with all the packages). (我知道它与所有软件包捆绑在一起)。

But I don't really get the problem I am facing in Octave. 但我真的没有遇到我在Octave面临的问题。 I use the QtOctave interface and there is a option there to install packages. 我使用QtOctave接口,有一个选项来安装包。 Is there some way to check for installed packages? 有没有办法检查已安装的软件包? Are they actually getting installed? 他们真的安装了吗?

I tried the same code in FreeMat and it gave some error there too. 我在FreeMat中尝试了相同的代码,它也有一些错误。

Here is my code: 这是我的代码:

% 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]);

Please help me to get this code to work on Octave. 请帮助我将此代码用于Octave。

Works for me. 适合我。 See https://saturnapi.com/fullstack/plotting-square-and-sawtooth-in-octave 请参阅https://saturnapi.com/fullstack/plotting-square-and-sawtooth-in-octave

If you're using Ubuntu, make sure to install the necessary package a la 如果你正在使用Ubuntu,请确保安装必要的包a la

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

在此输入图像描述

Have you actually loaded the packages of interest? 你真的加载了感兴趣的包吗? Even though the packages are installed, they may not be loaded into your particular Octave session. 即使安装了软件包,它们也可能无法加载到您的特定Octave会话中。 You can do this by typing pkg load <package_name> at the Octave prompt replace <package_name> by the corresponding paccage name. 您可以通过在Octave提示符下键入pkg load <package_name>替换<package_name> ,并使用相应的paccage名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM