2
votes

I wish to use an if-else flow block (or a custom matlab function that does it) in SIMULINK and use embedded coder to generate code for it. I had previously encountered a problem with zero and one-based indexing with MATLAB function blocks used in SIMULINK. It seems that there is practically no way around it. How can I model a if-elseif logic in SIMULINK then?

I have tried to use switch and mux blocks but they are too messy and could result into misinterpretation of original flow logic that I am trying to implement.

My flow logic (PSEUDOCODE) is:

if (a<b) then
    p = x;
else if (a<c) then
    p = max(y, some_const_val);
else
    p = z;

Could someone please suggest a way?

KR,

1

1 Answers

1
votes

Your pseudocode should work as a MATLAB Function block (which supports code generation for the subset of MATLAB function). I can't really see any issues with zero and one-based indexing??

For more complicated logic, Stateflow is a very powerful tool, but then it's an add-on so you need to fork out more money if you don't already have it. I agree though that, apart for very simple logic algorithms, a purely Simulink=blocks approach can become very quickly cumbersome.