필터 지우기
필터 지우기

how can i modify this code to use in Stateflow?

조회 수: 2 (최근 30일)
kadri
kadri 2013년 6월 2일
for s2=1:b
for s1=1:b-1
if m(1,s1)>m(1,s1+1)
c=m(1,s1);
m(1,s1)=m(1,s1+1);
m(1,s1+1)=c;
end
end
end
How can i generate this code in Stateflow Chart without using Matlab embeded function block. i have vector such as m=[0 1 2 3 4 5 6 7 8 9 10 ] and i m planning to use code that above to sort numbers in ascending order.
thank you.

답변 (2개)

Siddharth
Siddharth 2013년 6월 3일
If you are building your state machine in R2012b or newer, use the new chart block that uses MATLAB. In that block you can directly use MATLAB functions in the state actions/conditions. In your example, you could replace the loops with a call to the MATLAB function
sort
in the state diagram. Or you could write the loops directly in the state diagram too. Learn more about the chart block that uses MATLAB here: http://www.mathworks.com/videos/matlab-as-the-action-language-70059.html
  댓글 수: 1
kadri
kadri 2013년 6월 3일
thank you for your answer but i have to use stateflow chart, cuz calling Matlab function is not allowed to do this challenge.
My main problem is about this code, i can't generate for loop in for loop (two for loop) with stateflow charts. Could you give me example how can i create two for loop with stateflow charts?
thank you.

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


Siddharth
Siddharth 2013년 6월 17일
If you are not allows to use MATLAB functions, use graphical functions to achieve the same functionality. Find more information on how to create for loops using graphical functions here .

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by