0

I am just not able to figure out how to proceed:

I am trying to build a model:

  • It would have 4 Inputs ( Boolean i/p)
  • It would have 1 output (Signed: 8 bit)

It would perform the following:

  • Based on which input is 1, it would give a corresponding output reflecting the DataRate.

If I have to write in Matlab, I would write something like this :

if (portA==1)
    PSDU_Data_Rate=1;
    elseif(portB==1)
        PSDU_Data_Rate=2;
    elseif (portC==1)
        PSDU_Data_Rate=5.5;
    elseif(portD==1)
        PSDU_Data_Rate=11;
end

I am attaching, the part of the model which I am developing for the same functionality:

Data Rate Calculate

Any idea on how to proceed or code correction or suggestion on how it can be improved would be really helpful.

Thanks

Kiran
  • 8,034
  • 36
  • 110
  • 176

1 Answers1

0

Since you have 4 distinct inputs instead of a single input carrying an enumerated value, use If - Else, instead of a Case statement. I'm adding screenshots of how this can be done. Note that the If block also lets you have an Else output if you want to select one of the data rates by default (if none of the inputs are non-zero).

If block settings:

  • Number of inputs: 4
  • If expression: u1 ~= 0
  • Elseif expressions: u2 ~=0, u3 ~= 0, u4 ~= 0

The model consists of an If block connected to a set of If Action Subsystem blocks. The outputs of the latter can be combined into a single signal using a Merge block.

Top-level model

One of the If Action Subsystems

Praetorian
  • 106,671
  • 19
  • 240
  • 328