Prev: Converting Binary images/Grayscale images to move frames
Next: Speech Signal Separation for Voice/Unvoice parts
From: David Paixao on 1 Dec 2009 13:26 Hello, I am trying to run this progam on Matlab 7.8 but I keep getting this error message for about an hour... script file is: function y = simpson(f,a,b,n) b=5; a=1; n=5; h=(b-a)/n; x=linspace(a,b,n+1); fx=feval(fsimpz2,x); y=h/3*(fx(1)+4*sum(fx(2:2:n))+2*sum(fx(3:2:n-1))+fx and function file is: function y = fsimpz(x) y = 2*x; which is saved under the name fsimpz2 why do I get this message? How do I solve this? Thanks a lot!
From: TideMan on 1 Dec 2009 13:52 On Dec 2, 7:26 am, "David Paixao" <davidpaix...(a)hotmail.com> wrote: > Hello, > > I am trying to run this progam on Matlab 7.8 but I keep getting this error message for about an hour... > > script file is: > > function y = simpson(f,a,b,n) > > b=5; > a=1; > n=5; > > h=(b-a)/n; > x=linspace(a,b,n+1); > fx=feval(fsimpz2,x); > > y=h/3*(fx(1)+4*sum(fx(2:2:n))+2*sum(fx(3:2:n-1))+fx > > and function file is: > > function y = fsimpz(x) > y = 2*x; > > which is saved under the name fsimpz2 > > why do I get this message? How do I solve this? > > Thanks a lot! You can't use feval like that. You need to read the documentation on anonymous functions.
From: Bruno Luong on 1 Dec 2009 14:18 "David Paixao" <davidpaixao2(a)hotmail.com> wrote in message <hf3n3u$l0g$1(a)fred.mathworks.com>... > fx=feval(fsimpz2,x); > Try: fx=feval(@fsimpz2,x); @fsimpz2 means -> the function named "fsimpz2" fsimpz2 means -> call this function - without argument - thus the error Bruno
From: Steven Lord on 1 Dec 2009 14:24
"David Paixao" <davidpaixao2(a)hotmail.com> wrote in message news:hf3n3u$l0g$1(a)fred.mathworks.com... > Hello, > > I am trying to run this progam on Matlab 7.8 but I keep getting this error > message for about an hour... > > script file is: > > function y = simpson(f,a,b,n) > > b=5; > a=1; > n=5; Note that these are replacing the values that you passed in as input when you called your simpson function; if you wanted to use these as the "by default, if the user doesn't specify other values" values take a look at NARGIN. If not, just get rid of those three lines. > > h=(b-a)/n; > x=linspace(a,b,n+1); > fx=feval(fsimpz2,x); This line attempts to evaluate fsimpz2 with 0 input arguments (which is why you receive the error message you reported) and 1 output argument, then call FEVAL with 2 inputs. The first input to the FEVAL call is the output argument from fsimpz2 and the second is the x created by your LINSPACE call. Now I'm assuming you're passing a function handle to fsimpz2 into your simpson function when you call it. In other words, the way you're calling simpson is something like: y = simpson(@fsimpz2, 1, 5, 5); If so, replace the line where you define fx with: fx = f(x); or, if you want this to be backwards compatible to a time before we introduced the "feval-less" evaluation of function handles: fx = feval(f, x); If my assumption is incorrect, that's the way I recommend you call it. Take a look in the documentation for "function handles" for more information about them. They're a pretty powerful technique, especially when you're writing a function that's supposed to operate on other functions (a "function function") like you are. > y=h/3*(fx(1)+4*sum(fx(2:2:n))+2*sum(fx(3:2:n-1))+fx > > and function file is: > > function y = fsimpz(x) > y = 2*x; > > which is saved under the name fsimpz2 Best practice is to have the name of the file and the name of the main (first) function in the file be the same. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ |