How to process elements in an array using stateflow if-statement?

조회 수: 7 (최근 30일)
xiao
xiao 2017년 2월 14일
답변: Muthukumar Ganesan 2022년 7월 31일
I have a simple if-statement code:
A=[1 3 10 20];
for i=1:length(A)
if A(i)>10
A(i)=10;
end
end
Then the output is: [1 3 10 10] (20->10)
How could I achieve this using stateflow? I made a constant [1 3 10 20], and drawed a chart with if statement:
Diagnosis shows error in "Attempted to assign to Simulink input 'u'. Transition '{u=10}'", which makes sense because input u is an array. I think if the input is a bus signal then may work. How to define the input and output signal as bus? Thanks.
  댓글 수: 1
Saurabh Gupta
Saurabh Gupta 2017년 2월 17일
1) You don't need any loops or if statements in your problem. The following statement performs the same operation.
A(A>10)=10;
2) The error "Attempted to assign to Simulink input 'u'" means that you are trying to change the value of the input, which is not allowed. You should copy the value into another variable and make updates there. For example, you can start with "y=u" and then make changes in variable "y"

댓글을 달려면 로그인하십시오.

답변 (1개)

Muthukumar Ganesan
Muthukumar Ganesan 2022년 7월 31일
Hi,
In Stateflow with C action language without using a loop, you have to use Matlab function. i.e. Saurabh's answer can be used inside the inserted matlab function.
Thanks.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by