|
"BC Tan" <rainzz@live.com> wrote in message
news:hb0f22$fu$1@fred.mathworks.com...
> Hi, the code provided by you as show below
>
> function u=ut(t)
> t=0:.1:10;
Why allow ut to accept an input argument when you're just going to overwrite
it on the next line?
> u=t>=0;
> plot(t, ut(t-1) - ut(t-2))
Is this an attempt to recursively call ut or an attempt to plot u*t versus
t?
> results in the following error.
>
> ??? Undefined function or method 'ut' for input arguments of type
> 'double'.
>
> Error in ==> rect at 4
> plot(t, ut(t-1) - ut(t-2))
So the root cause for this specific error is that you've written a function
ut as the main (first) function inside the file rect.m -- when the names of
the file and the main function in that file differ, MATLAB will refer to the
function by the FILE name. So if you wanted this to be a recursive call,
you would need:
plot(t, rect(t-1) - rect(t-2))
but if you do that with the rest of the code written above, you will receive
a Recursion Limit error (as your code has no way to break out of the
recursion.)
Go back to the textbook where you learned the definition of a rect function.
Open an M-file and write the steps you need to follow to evaluate the rect
function for a given input as comments -- DO NOT write down any MATLAB code
at this stage. Once you have the steps written down, break any that you
don't know how to implement directly into substeps. Again, don't write any
code yet.
Once each comment corresponds to an instruction that you know how to
implement (and not before), implement them. Doing this, not only will you
get code that's more likely to work the first time, but you'll also
understand it better.
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|