欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Matlab排错:conversion to double from sym is impossile MatlabF#IDEAYahoo 

程序员文章站 2024-02-07 13:31:40
...
贴上答案,问题也是类似的:

"Nor Faizah " <a7khawarizmi@yahoo.com> wrote in message
news:flg079$77o$1@fred.mathworks.com...
> Hello everyone
>
> Actually i'm quite new to Matlab. I have a task on
> accessing some Matlab functions. At this moment, I try to
> look at the difference between the fourier transform which
> takes from -inf to inf and the fourier transform which
> takes from zero to inf.
>
> In order to do the latter part, I take the heaviside
> function and multiply with a cosine function (to start
> with). And find the fourier transform of the product.
>
> However, I don't have any idea how can I plot the result.
> Here is my try
>
> x=-10:0.1:10;
> %y = heaviside(x)
> % Heaviside(x) = 0, for x < 0
> % = 1, for x> 0
> y(x > 0) = 1;
> y(x == 0) = NaN;
> figure(1);plot(x,y); grid;
>
> g=cos(5*x);
> figure(2);plot(x,g);grid;
> G=y.*g;
> figure(3);plot(x,G);grid;
> F=fourier(G,w);

The FOURIER function is only defined for sym objects, so one or more of g,
y, or w must be a sym object. That means F will be a sym object as well,
and when you call PLOT two lines down from here ...

> ww=-10:0.1:10;
> figure(4);plot(ww,F);grid;
>
> And here is the Matlab response
> ??? Error using ==> plot
> Conversion to double from sym is not possible.

you receive this message, because PLOT doesn't know how to convert the sym
object into a double array for plotting. To correct this, you will need to
convert the sym object into a double array. The easiest way to do this, if
the expression F does not contain any instances of symbolic variables, is to
use double(F). If it does contain symbolic variables, use SUBS to
substitute values into that expression (and call DOUBLE on that result if
necessary.) Alternately, the EZPLOT function accepts sym objects and plots
them, so you could use that instead of PLOT.

Actually, thinking about this a little more, I don't think you want to use
FOURIER in this manner. Look in the M-file help for FOURIER -- it gives an
example that uses the Heaviside function directly, rather than passing a
vector of data to FOURIER.

--
Steve Lord
slord@mathworks.com