How can I multiply each bus element with a constant?

3 views (last 30 days)
I created a Bus with more than 1000 Signals. Is there a way to multiply each element (or parts of the bus) with a constant without using a busselector?

Answers (1)

Mark McBroom
Mark McBroom on 19 Mar 2017
This can be done easily with a ML Function block. Code in ML Fcn Block:
y = u; elemNames = fieldnames(u); for i=1:numel(elemNames) y.(elemNames{i}) = u.(elemNames{i})*2 + i; end
See atttached example.
  1 Comment
Alexander Gebel
Alexander Gebel on 21 Mar 2017
Hi, thank you for your answer.
I use Matlab R2014b.
While running your example i receive this error: "Function 'fieldnames' is not supported for code generation. Consider adding coder.extrinsic('fieldnames') at the top of the function to bypass code generation."
But i have to generate code for a rtw application.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!