How to turn off scientifc notation when using char command in Matlab?

148 Views Asked by At

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!

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

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

syms x;
y = x^2 + 0.0001*x;
char(vpa(y))

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