How to access a signal from a bus structure inside matlab function

1 回表示 (過去 30 日間)
Andy
Andy 2015 年 8 月 12 日
回答済み: Chaitali Gondhalekar 2015 年 8 月 14 日
Is it possible to select a signal from a bus structure inside a MATLAB function and then scale it and then assign it to an output?
e.g. some thing like the following:
function [output] = myfunc(input, signalSelection, scaling)
% #codegen
output = input(signalSelection)*scaling;
end
where input is a defined bus structure, signalSelection is a uint32 and scaling is a single?
The error I keep getting is "Function 'mtimes' is not defined for values of class 'struct'."

回答 (1 件)

Chaitali Gondhalekar
Chaitali Gondhalekar 2015 年 8 月 14 日
I understand that you want to access a single signal from a Bus structure in the MATLAB workspace.
Assuming that you are using "Simulink.Bus.createMATLABStruct" to create the Bus structure "input" mentioned in your code snippet, you can access its fields with a dot operator and scale it using the "scaling" parameter. For example, if your Bus structure has a signal "pulseSignal", you can access it as
>> output = input.pulseSignal * scaling
Hope this helps!

カテゴリ

Help Center および File ExchangeSources についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by