help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: undefined variable in a .m file


From: Quentin Spencer
Subject: Re: undefined variable in a .m file
Date: Wed, 11 Jul 2007 07:53:16 -0500
User-agent: Thunderbird 2.0.0.4 (X11/20070615)

malik martin wrote:
hi,
if i knew the syntax to declare a variable in matlab, then maybe i
wouldnt be asking this, but i get this error saying:

`a' undefined near line 5 column 11

in this code:

1   % Read input sound file into vector x(n) and sampling frequency FS
2   [x,FS]=wavread('ton2.wav');
3   % Sample-by sample algorithm y(n)=a*x(n)
4   for n=1:length(x),
5   y(n)=a * x(n); <------- ERROR IS HERE
6   end;
7   % Write y(n) into output sound file with number of
8   % bits Nbits and sampling frequency FS
9   wavwrite(y,FS,Nbits,'tonealg.wav');

You define a variable by assigning something to it. Try something like

a=2;

before line 5, and it should work. By the way, your for loop in lines 4-6 is inefficient. You can do the same thing using the command

y = a * x;



Quentin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]