End a Program in MATLAB with Error-Checking: Troubleshooting Tips

  • Context: MATLAB 
  • Thread starter Thread starter Jelfish
  • Start date Start date
  • Tags Tags
    Matlab Program
Click For Summary

Discussion Overview

The discussion revolves around how to properly end a MATLAB program with error-checking when a specific condition regarding matrix and vector sizes is not met. Participants explore various methods to achieve this, including printing error messages and terminating the program execution.

Discussion Character

  • Technical explanation, Debate/contested, Homework-related

Main Points Raised

  • One participant seeks a function to terminate a MATLAB program upon detecting an error condition in an if-statement.
  • Another participant humorously acknowledges the error message but does not provide assistance with the MATLAB query.
  • A different participant suggests using the 'error' function to terminate the program and print a custom error message.
  • Another suggestion includes using the 'return' command if the context involves a function with defined output variables.
  • A participant mentions that there is a method to end the MATLAB executable but admits to not having used MATLAB for three years.
  • A later reply confirms that the 'error' function is the solution needed for the original query.

Areas of Agreement / Disagreement

Participants express various methods to handle program termination, but there is no consensus on a single best approach. Multiple suggestions are presented, indicating differing opinions on how to implement error-checking in MATLAB.

Contextual Notes

Some responses may depend on specific contexts, such as whether the code is part of a function or a script. The effectiveness of suggested methods may vary based on the user's familiarity with MATLAB.

Who May Find This Useful

Individuals working with MATLAB who are looking for error-checking techniques and methods to gracefully terminate programs in response to specific conditions.

Jelfish
Messages
148
Reaction score
5
Hi

I've been trying to figure this out for a bit and thought one of you might know the answer off the top of your head.

I have an if-statement in my MATLAB program that error checks a matrix and vector size. I want the program to print an error message and then end the program (like a ctrl-c) if the error condition is satisfied. Something like this:

Code:
if a~=b
fprintf('STFU N00B');
??
end
% other stuff

where ? is the function the would end the program. Does such a function exist, and if so, what is it?

Thanks in advance.
 
Last edited:
Physics news on Phys.org
STFU NOOB? Heh heh heh...That's funny. Sorry I can't help on the Matlab part.
 
Jelfish said:
Hi
I've been trying to figure this out for a bit and thought one of you might know the answer off the top of your head.
I have an if-statement in my MATLAB program that error checks a matrix and vector size. I want the program to print an error message and then end the program (like a ctrl-c) if the error condition is satisfied. Something like this:
Code:
if a~=b
fprintf('STFU N00B');
??
end
% other stuff
where ? is the function the would end the program. Does such a function exist, and if so, what is it?
Thanks in advance.
Code:
if a~=b
fprintf('STFU N00B');
error('u R not 1337')
end
% other stuff
 
if you are writing a function, your output variables have been defined, and you want them passed, you can also use the 'return' command.
 
yes there is a breaker that ends the MATLAB exe...unfortunately i haven't played with MATLAB for 3 years.
 
LeBrad said:
Code:
if a~=b
fprintf('STFU N00B');
error('u R not 1337')
end
% other stuff

Thanks, Brad! That's exactly what I needed. LeBrad = awesome;

And thanks to everyone else too
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
Replies
1
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K