【问题标题】:Jump to next statement within if statement in Matlab在 Matlab 中的 if 语句中跳转到下一条语句
【发布时间】:2014-05-19 16:47:08
【问题描述】:

我知道这是一种非常糟糕的编程风格,但我现在需要它快点。

我需要的是从 elseif 中跳转到“else”,而无需再次运行整个代码大量计算代码。有人知道怎么做吗?

我无法重写整个结构,也不想编写一个子函数来调用 if 语句中的 else 计算,因为这是一个需要大量输入元素的计算。

我的快速而肮脏的解决方案必须再次运行大量计算:

flag = 0; 

while a>1
   *tons of calculating code*

  if statement1

   *random calculation*

  elseif flag==0

    *calculation*

    if statement2 %Depends on whats happening in *calculation*
       flag = 1;
       continue
    end

  else 
  flag = 0;
  *calculations*
  end

end

最好的问候:)

【问题讨论】:

  • 把else改成if ~statement1&&flag==1?
  • 有时我只见树木不见森林。谢谢!

标签: matlab if-statement coding-style goto


【解决方案1】:

来自丹尼尔:

将 else 改为 if ~statement1||flag==1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多