Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何完全停止matlab程序的执行?AEP等效于';错误';,但不会抛出错误_Matlab_Return_Exit_Execution - Fatal编程技术网

如何完全停止matlab程序的执行?AEP等效于';错误';,但不会抛出错误

如何完全停止matlab程序的执行?AEP等效于';错误';,但不会抛出错误,matlab,return,exit,execution,Matlab,Return,Exit,Execution,我有以下几行代码: someFunction disp('This should not be executed, if condition in someFunction is true') function someFunction if condition % what do I have to write here so the disp command is not executed? % return does not do it. I don't want to throw

我有以下几行代码:

someFunction
disp('This should not be executed, if condition in someFunction is 
true')


function someFunction
if condition
% what do I have to write here so the disp command is not executed?
% return does not do it. I don't want to throw an error.  quit/exit 
% are also not what I want..
end

在if条件块中需要什么语句,以便在条件为true时不执行disp语句<代码>错误('some error')就可以了。但我不想犯错误

可能是我没有正确地理解这个问题,我推荐一种在C中用于设备接口的方法。让我们建议我们有一个函数,它调用与设备通信并返回int值的其他函数:deviceOk(通常为0)或错误代码。如果任何内部函数失败,我们应该终止调用函数并转到资源管理。结果函数充满了检查,嵌套的或顺序的

function isOk = mainFcn()
isOk = false; 
% awaiting a bad result is better if we suppose a crash or exception somewhere inside, but wan a clean exit
[isOk , result] = someFcn(input);
if (~isOk)
   disp('If everything was OK, I'd never see this message');
end
end

function [isOk, result] = someFcn(input)
isOk = false; %preallocate inputs to error and modify only if really needed
result = Nan;
if isnan(result)
   return;
end
end

可能对您有用?通常的方法是使用
someFunction
返回的参数。如果这不能解决您的问题,您需要详细说明原因。@gnovice是的,这确实很有帮助。但对于我的案例来说,那里的方法很复杂。我将在someFunction中使用返回的参数。。aka
isOk=someFunction
是的,看起来这是一条路。。我希望有一个简单的命令可以像control+c一样工作,只是在代码中。但事实似乎并非如此。。我现在就用你的方法。事实上,在FEX中有一个
goto
,但我不认为它会更好