How can I multiply each bus element with a constant?

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)

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

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

Asked:

on 1 Mar 2017

Commented:

on 21 Mar 2017

Community Treasure Hunt

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

Start Hunting!