Nesting for loops and if statements in MATLAB

2 ビュー (過去 30 日間)
athpapa -
athpapa - 2011 年 3 月 21 日
I have a program in MATLAB that I use two for loops e.g.:
for ....end
for...end. In the 2nd 'for loop' I use an if statement to set a constraint. And I want this if loop to call the first 'for loop' of the program and then continue with the second loop. I mean:
for
...
end
for
if..
call 1st 'for loop'
end
...
end
Is there any way to do this??
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 12 月 8 日
There is no such thing as an if loop.

サインインしてコメントする。

回答 (2 件)

Timothy Felty
Timothy Felty 2011 年 3 月 21 日
I'm not sure if I understand correctly, but you could put the first for loop into a function.
Function main_func()
loop_one(params)
For
If
loop_one(params)
End
End
End Function
Function loop_one(params)
For
End
End Function

Matt Fig
Matt Fig 2011 年 3 月 21 日
Put the first FOR loop in a function. Then, in your program, call the function, enter the second FOR loop, evaluate the condition and decide whether or not to call the function.
EDIT
You say you tried, but get an error. What did you try and what was the error?? Show simplified code of what you have and what you tried.
  1 件のコメント
athpapa -
athpapa - 2011 年 3 月 21 日
how can I put the for loop in a function and how I call it to my script? I try it but always get an error!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by