How to exit a matlab m-file (NOT the matlab itself) if the user enters bad inputs?
I know if a m-file goes wrong at run time we can press Ctrl-C to stop it. but I need a command to put it in my m-file to do so if something bad happens.
Please don’t suggest ‘exit’ or ‘quit’ commands as they terminate the entire matlab and I don’t want it.
You can just put a error command like error(‘bad user input’) and it should stop the script.
Edit: alternatively, you could just refactor your code to not run unless you set the input flag to be true. Something like