Return control form a function to the main program
Mostrar comentarios más antiguos
So I have a function (say xyz.m) with inputs and outputs (integers and strings). I specify an 'if' condition, and if it not satisfied, then I want my program to discontinue executing any more lines from the function (xyz.m) and return the control to the very next line of my main program (let us call the main function as main.m). I tried using the syntax 'return' but it gives me an error because the variables that were supposed to be returned/filled by the function are not assigned (like this: ??? Output argument variable (and maybe others) not assigned during call <function.). So is there any other sytanx or command that does the job (something as simple as 'break' which simply quits the 'for' or 'while' loop). Thanks in advance.
Respuesta aceptada
Más respuestas (1)
Fangjun Jiang
el 13 de Jun. de 2011
0 votos
Even if such command or function exists, you still have the problem that the return variables of your xyz.m have not been set yet. xyz.m may have multiple return variables such [x, y,z]=function xyz. A good practice is to initialize or set the default value for x, y and z at the begining of your xyz.m so you won't have that problem.
1 comentario
Dhaval
el 15 de Jun. de 2011
Categorías
Más información sobre Entering Commands en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!