1

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

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • @dfri I would recommend explicitly calling out the ASCII character you removed in your edit, since it's what is causing the error – sco1 Mar 02 '16 at 16:20
  • @excaza Ow, my bad, didn't realize I removed the part of interest. I'm still a bit unsure what part I messed up, could you possibly fix this with an edit, or should I just backroll to rev1? Thanks for pointing this out. – dfrib Mar 02 '16 at 16:21
  • I tried to fix the question SO seems to filter these special chars. I had to copy it directly from the source code of the question to reproduce the problem. – Daniel Mar 02 '16 at 16:25
  • @Daniel Seems like I didn't explicitly remove it, but that the SO code formatting did? I'm confused, as I can find it in the raw source of rev1 but not rev2. – dfrib Mar 02 '16 at 16:25
  • The original code can be found here: http://pastebin.com/SyEHKpjR . I am unable to get any useful formatting for this question. – Daniel Mar 02 '16 at 16:28
  • My apologies for messing up the original post w.r.t. the single part of interest; I've tried to redeem it with the editors note above, but haven't been able to re-introduce the original _start of text_ character, not even by roll-back to revision 1. – dfrib Mar 02 '16 at 16:39
  • thanks all for helping me out of this :) really helpful – Nugroho Permata Putra Mar 02 '16 at 16:41
  • @dfri: I knew what I was searching, I used the [source view](http://stackoverflow.com/revisions/ae792bf1-fa4a-4f03-aff9-e5ddc8e8f227/view-source) of the question instead of trying to format it. In the rendered version it was not available as well, that's why a roll-back did not help. – Daniel Mar 02 '16 at 19:07

1 Answers1

4

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.

Community
  • 1
  • 1
Daniel
  • 36,610
  • 3
  • 36
  • 69
  • damn it was a "space" between t= -2. Now i get it, it Works!! thanks – Nugroho Permata Putra Mar 02 '16 at 16:30
  • nice one! I copied the code and could not recreate it, didn't realize it could have been a special char in there. – GameOfThrows Mar 02 '16 at 16:33
  • @GameOfThrows: In the [original version](http://stackoverflow.com/revisions/ae792bf1-fa4a-4f03-aff9-e5ddc8e8f227/view-source) of the question you can clearly see the `|` pointing to the problem. Then I knew what I was searching. – Daniel Mar 02 '16 at 19:02