I want to convert a polynomial expression into an array of characters in MATLAB. We are using the command char. On my computer, char will change the format of the coefficients of a polynomial to scientific notation.

For example,

char(x^2 + 0.0001*x)

will output $x^2 +1e-4\cdot x$ as an array of chars. That will generate an error in my program.

Can we get an array which contains $x^2+0.0001\cdot x$ of length $12$ instead of an array containing $x^2+1e-4\cdot x$ which is of length $10$ by using char? If there is a way of turning off the scientific notation in MATLAB, that will be great!


  • $\begingroup$ char(x^2 + 0.0001*x) does not return x^2 +1e-4*x, it returns the char that corresponds to the value of $x^2+0.0001x$. Do you simply want the string x^2+0.0001*x? Then just write 'x^2+0.0001*x'. $\endgroup$ – Eff Oct 31 '14 at 20:39
  • $\begingroup$ It returns an array of chars. x^2 + 0.0001*x is a symbolic expression which has no value. x is a variable defined by syms x. This is an example, I would like to do that for any input polynomial f by char(f). $\endgroup$ – Pew Oct 31 '14 at 20:51
  • $\begingroup$ Do you use syms x or what? And then char(x^2 + 0.0001*x) returns the $1$ by $10$ array of chars x^2+1e-4*x? $\endgroup$ – Eff Oct 31 '14 at 20:55
  • $\begingroup$ Yes, I use syms x, and it returns 1 by 10 array of chars x^2+1e-4*x $\endgroup$ – Pew Oct 31 '14 at 21:40

Try converting your symbolic expression to variable precision arithmetic using vpa before using char:

syms x;
y = x^2 + 0.0001*x;

See the documentation for vpa and for digits for how to adjust the conversion.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.