Matlab排错:conversion to double from sym is impossile

贴上答案,问题也是类似的:

"Nor Faizah " <[email protected]> wrote in message
news:[email protected]...
> 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
[email protected]

你可能感兴趣的:(Yahoo,F#,matlab,idea)