How can I compose an output structure with a mixed selection of values from two input structs in MATLAB?

1 view (last 30 days)
I'm making a model in MATLAB/Simulink, and i've got to output a CAN bus to a device to manipulate it. I'm composing that CAN bus with either signals that I get from a vehicle's CAN bus, or signals from my model simulation. I'm effectively injecting CAN signals in a communication from a vehicle to one of its devices.
I must be able to switch individual input signals, so if I would have 4 signals from the vehicle, and also 4 from my simulation, I must be able to have output select the first two signals from the vehicle, and the last two from my model. Schematically, it looks like this:
structSwitch.png
But as inputs, i've got two structs with the same subnames, size and layout, both with multiple (sub)fields, and around 500 values in total per struct. The output is a again a struct in that same size and layout that is a mixed selection of values from either one of the input structs.
So for one example: output VEH.SteeringColumnSwitch.HighBeam must be copied from either input VEHCAN.SteeringColumnSwitch.HighBeam or input VEHSIM.SteeringColumnSwitch.HighBeam, and so on for all 500 signals.
I'm thinking about having my model import an Excel sheet that allows the user to toggle between sources(model/vehicle) of the input signal. I'm not that skilled in programming, but I feel that using a huge amount of eg. switch case statements wouldn't be efficient nor easy to handle.
How can I (efficiently)compose an output structure with a mixed selection of values from two input structs in MATLAB?

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!