How can I display an error message in MATLAB?

I was making a model for the crank slider mechanism, and I wanted to show an error when the length of the crank exceeds the length of the sliding lever. When the crank length r2and slider r3, my code is as follows:

if r3=<r2
    error('The crank length cannot exceed that of the slider')
end

I get an error message:

???     error('The crank length cannot exceed that of the slider')
                         |
Error: Unexpected MATLAB expression.

can someone tell me what i am doing wrong and how to fix it?

+5
source share
3 answers

If you want to use a character 'in a string, you need to add one more before it '(note the example in the documentation ):

if (r3 <= r2)
  error('The crank' length cannot exceed that of the slider');
end

Also note the change I made from =<to <=.

+11

, <= , ​​

', ''

+2

You can also print to the error descriptor:

fprintf(2,'The crank' length cannot exceed that of the slider');
+2
source

All Articles