How do i use and index an array in an "else-if" expression in Simulink?

1 view (last 30 days)
I have a Matrix of Values that i want to use in an "else-if" expression of an If-Block
Is it only possible to index a list e.g. L(1) but not an matrix e.g. L(1,1) in this scenario? Because Simulink sees the comma as the start of the next expression.
% Possible
u1>=L_R(1) & u1<L_R(2),
% Not Possible
u1>=L_R(1,1) & u1<L_R(2,1),
Error: "The expression u1 >= L(2" has a syntax error
Does anyone have an idea for a Workaround?

Accepted Answer

Benjamin Thompson
Benjamin Thompson on 25 Jan 2022
Edited: Benjamin Thompson on 25 Jan 2022
What is L_R? I do not think the if subsystem block in Simulink allows any symbols other than uN, where N is between 1 and the number of inputs you put in the block mask. If L_R is like a model workspace parameter or something like that, can you just add a second input to the if block (or more than 1) and let the block handle all of them as uN, replacing all L_R references with ua, ub, uc, etc. The block probably won't accept a matrix as an input.
  2 Comments
Benjamin Thompson
Benjamin Thompson on 25 Jan 2022
Use a constant block to access L_R(1,1) and pass it to the input of an if block.
S.L.
S.L. on 26 Jan 2022
L_R is a matrix saved in the workspace.
The idea with the constant Block is great. It works just fine, a pitty that it doesnt look that clean when you have a lot of inputs.
My workaround was to use linear indexing, which also worked, but had its toll on the code performance! So i am going to use your solution.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!