Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.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 如何将控件移动到“的其他部分”;如有其他",;当';如果';部分_Matlab - Fatal编程技术网

Matlab 如何将控件移动到“的其他部分”;如有其他",;当';如果';部分

Matlab 如何将控件移动到“的其他部分”;如有其他",;当';如果';部分,matlab,Matlab,是否有一种方法可以设置条件,以便在if下的语句/矩阵中出现错误时,执行else下的语句 i、 e 没有内置机制可跳转到else部分。但您可以使用如下构造: condition_flag = (some condition); error_flag = false; if condition_flag try some statment1/matrix1/variable1 some statement2/matrix2/variable2

是否有一种方法可以设置条件,以便在
if
下的语句/矩阵中出现错误时,执行
else
下的语句

i、 e


没有内置机制可跳转到
else
部分。但您可以使用如下构造:

condition_flag = (some condition);
error_flag = false;

if condition_flag
    try
        some statment1/matrix1/variable1 
        some statement2/matrix2/variable2
        some statement3/matrix3/variable3
    catch
        error_flag = true;
    end
end

if ~condition_flag || error_flag
    %if any of the statements 1,2 or 3 under if condition yields any error  like dimension mismatch or anyother
    ....
    error_flag = false;
end

莫森·诺斯特拉尼亚的替代方案

else_flag=true;
if (condition)
  try
    %% The if code
    else_flag=false;
  end
end
if else_flag
  %% The else code
end
else_标志=false条件
为真且
内未发生错误时,才会执行code>命令


请注意,这两种解决方案实际上都是您想要的-执行
命令直到出现错误,然后执行

如果要减少
If
语句的数量:

try
  if statement
    %% The if code
  else
    %% Obvious error
    a(0);
  end
catch
  %% The else code
end

您的try-catch块缺少一个catchstatement@Matt我知道。如果您不关心错误详细信息,则可以取消显示警告
缺少catch语句
,并忽略它。如果应执行捕获序列,则将执行else代码。
try
  if statement
    %% The if code
  else
    %% Obvious error
    a(0);
  end
catch
  %% The else code
end