我是靠谱客的博主 健壮砖头,最近开发中收集的这篇文章主要介绍matlab do while,Do While Loop,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

C Construct

num_iter = 1;

do {

flag = func();

num_iter++;

}

while (flag && num_iter <= 100)

Modeling Pattern for Do While Loop: While Iterator Subsystem block

One method for creating a do while loop is to use a While Iterator Subsystem block from the Simulink > Ports and Subsystems library.

1. Open example model ex_do_while_loop_SL.

777a7f3ee3b3b791a9c6ca13dc4a9269.png

The model contains a While Iterator Subsystem block that repeats execution of the contents of the subsystem during a simulation time step.

Observe the following settings in the While Iterator Subsystem:

The func subsystem block has an output flag of 0 or 1 depending on the result of the algorithm in func( ). func() is the Function name in func subsystem.

For the While Iterator block, the Maximum number of iterations is 100.

For the While Iterator block, the While loop type is do-while.

2. To build the model and generate code, press Ctrl+B.

The code implementing the do while loop is in the ex_do_while_loop_SL_step function in ex_do_while_loop_SL.c:

/* Model step function */

void ex_do_while_loop_SL_step(void)

{

int32_T s1_iter;

/* Outputs for Iterator SubSystem: '/While Iterator Subsystem' incorporates:

* WhileIterator: '/While Iterator'

*/

s1_iter = 1;

/* SystemReset for Atomic SubSystem: '/func' */

func_Reset();

/* End of SystemReset for SubSystem: '/func' */

/* End of Outputs for SubSystem: '/While Iterator Subsystem' */

do {

func();

s1_iter++;

} while (flag && (s1_iter <= 100));

}

Modeling Pattern for Do While Loop: Stateflow Chart

1. Open example model ex_do_while_loop_SF.

eb20ec9ef3c2e11fc5abb9913c4b305f.png

In the model, the ex_do_while_loop_SF/Chart executes the do while loop.

2f83849ac3f44094205e735d64082b71.png

The chart contains a While loop decision pattern that you add by selecting Chart > Add Pattern in Chart > Loop > While.

2. To build the model and generate code, press Ctrl+B.

The code implementing the do while loop is in the ex_do_while_loop_SF_step function in ex_do_while_loop_SF.c:

/* Model step function */

void ex_do_while_loop_SF_step(void)

{

int32_T num_iter;

/* Chart: '/Chart' */

num_iter = 1;

do {

func();

num_iter++;

} while (flag && (num_iter <= 100));

}

最后

以上就是健壮砖头为你收集整理的matlab do while,Do While Loop的全部内容,希望文章能够帮你解决matlab do while,Do While Loop所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部