Nugroho Permata Putra
Nugroho Permata Putra

Reputation: 23

Error: The input character is not valid in MATLAB statements or expressions

I have an error when I try to run this on Matlab r2012b

t=-2:.1:5;
x=3*exp(0.4*t);
y=2*exp(-0.9*t);
plot(t,x,t,y,':');
legend('x(t)','y(t)')

Yielding the error:

>> t=-2:.1:5;
 t=-2:.1:5;
   |
Error: The input character is not
valid in MATLAB statements or
expressions.

Editors note:

First code line of original post contained a "hidden" character (single source of error) which was, due to SO formatting, lost in the first edit (intended to fix code formatting). Even when re-rolling back to revision 1, the "hidden" character is lost.

t={Character: ASCII Code 2}-2:.1:5;

Original code (thanks Daniel) can be found here

Upvotes: 1

Views: 4044

Answers (1)

Daniel
Daniel

Reputation: 36710

In your code the third char of t=-2:.1:5; is not a whitespace (ASCII Code 32) like MATLAB displays it, it is a start of text (ASCII Code 2). I have no idea how these control chars got into your code, but to clean it up I recommend a text editor which allows to display all hidden chars.

Upvotes: 4

Related Questions