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
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 25K views
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
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
 
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