필터 지우기
필터 지우기

How to write a for loop inside an if loop

조회 수: 2 (최근 30일)
Roy Francis
Roy Francis 2014년 10월 30일
답변: Julia 2014년 10월 30일
I am using simulink user defined function for the control applications. The code does not execute correctly, only the first line executes and remaining code is not getting executing. The code is shown below:
function [Vo,ftw,Rc_ctrl,Dir] = fcn(C,S0,S1,S2)
Vo = 0.20; ftw = 10; Rc_ctrl = 0; Dir = 0;
if (S0 == 1) && (S1 == 1) && (S2 == 1) && (C <= 2000000)
for i=2000000:50000:3500000
if ( (C > i) && (C <= i+50000))
Vo = Vo+0.02; ftw = ftw+1; Rc_ctrl = 0; Dir = 0;
end
end
end
The variable C is a counter input which counts from 0 to 3500000 at an increment step of 50000. The function inputs S0,S1,S2 are input to the user defined function.
While executing the code only first line executes and remaining lines not getting executing.
Thanking you in advance for your valuable suggestions !!!
Roy

답변 (1개)

Julia
Julia 2014년 10월 30일
Hi,
your first if statement condition includes C<=2000000 but your second if statement wants C to be greater than i, which starts with i=2000000. That's a contradiction.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by