Wednesday, 2 October 2013

Plotting square() and sawtooth() in Octave

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
>>>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! (I know it comes bundled with
all the packages).
But I don't really get the problem I am facing in Octave. I use the
QtOctave interface and there is a option there to install packages. 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.
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.

No comments:

Post a Comment