Matlab排错:conversion to double from sym is impossile
2008-03-17 13:30
531 查看
贴上答案,问题也是类似的:
"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
"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
相关文章推荐
- Conversion to double from cell is not possible.
- 编译emule 源代码error C2520: conversion from unsigned __int64 to double not implemented 安装VS6SP5+VCPP5解决问题
- How to eliminate the compile error "conversion from 'double ' to 'float ', possible loss of data"
- Java Conversion from String to bytes is not one-one?
- [Tip: double string]Conversion from string to built-in types like double
- warning: deprecated conversion from string constant to "char *"
- invalid conversion from 'void* (*)()' to 'void* (*)(void*)'
- warning: deprecated conversion from string constant to "char *"
- 20110116 About the prosody conversion from neutral speech to emotional speech
- java.sql.SQLException: null, message from server: "Host '192.168.1.101' is not allowed to connect
- no known conversion for argument 1 from ‘[some_class]' to ‘[some_class]&’ 传const引用而非引用
- Permission Denial: null asks to run as user 1771 but is calling from user 0; this requires android.p
- Using Timer to get history values from EDNA database, an error is prompted in the page : "Sys.WebForms.PageRequestManagerTimeout
- message from server: "Host 'xxx' is not allowed to connect to this MySQL server的解决
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to this MySQ
- 远程mysql_java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- warning:deprecated conversion from string constant to 'char *'
- Stack Overflow requires external JavaScript from another domain, which is blocked or failed to load.
- warning: deprecated conversion from string constant to "char *"
- message from server: "Host xxx is not allowed to connect to this MySQL server的解決