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

3 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Sources 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by