Implement data type propagation for custom block
After some discussion and playing around, I got some ways in defining a block mask that sets the Simulink (fixed point) data type of an output. i have a mask parameter called "quotype" that is a Data Type parameter, and I can pass a related parameter into my MATLAB Function block that has that data type which can then be acted upon. However, I’d like to support rules such as "Inherit: Inherit via internal rule" and "Inherit: Inherit via back propagation". To do so, I need to be able to retrieve information on the signals/ports as they’re compiling in Mask call back function. To wit: I have the current code that for instance works correctly when a specific data type is invoked:
% Initialization code section
function initialization()
if ~isa(quotype,’Simulink.NumericType’)
ports = get_param(gcb,"PortHandles");
out1 = ports.Outport(1);
in1 = ports.Inport(1);
in2 = ports.Inport(2);
disp(ports)
switch quotype
case ‘Inherit: Inherit via internal rule’
ttmp = fixdt(0,10,2);
case ‘Inherit: Inherit via back propagation’
ttmp = fixdt(0,10,2);
case ‘Inherit: Same as first input’
ttmp = fixdt(0,10,2);
otherwise
disp(quotype)
ttmp = fixdt(0,10,2);
end
qtype = fi(0,ttmp);
else
qtype = fi(0,quotype);
end
end
So, if a specific numeric type is provided in the dialog, I see I get a Simulink.NumericType object and life is good. If one of the other rules is selected, I get a string. As you can see, I can access stuff like the block port handles, but they’re doubles not objects so I have no idea what to do next. I can’t run this in the debugger apparently so I’m limited to my disp() statements that put stuff in the Diagnostic Viewer. The qtype is passed as a parameter into the underlying MATLAB function and the numeric type can be re-fetched by the call fixed.extractNumericType().
Help!After some discussion and playing around, I got some ways in defining a block mask that sets the Simulink (fixed point) data type of an output. i have a mask parameter called "quotype" that is a Data Type parameter, and I can pass a related parameter into my MATLAB Function block that has that data type which can then be acted upon. However, I’d like to support rules such as "Inherit: Inherit via internal rule" and "Inherit: Inherit via back propagation". To do so, I need to be able to retrieve information on the signals/ports as they’re compiling in Mask call back function. To wit: I have the current code that for instance works correctly when a specific data type is invoked:
% Initialization code section
function initialization()
if ~isa(quotype,’Simulink.NumericType’)
ports = get_param(gcb,"PortHandles");
out1 = ports.Outport(1);
in1 = ports.Inport(1);
in2 = ports.Inport(2);
disp(ports)
switch quotype
case ‘Inherit: Inherit via internal rule’
ttmp = fixdt(0,10,2);
case ‘Inherit: Inherit via back propagation’
ttmp = fixdt(0,10,2);
case ‘Inherit: Same as first input’
ttmp = fixdt(0,10,2);
otherwise
disp(quotype)
ttmp = fixdt(0,10,2);
end
qtype = fi(0,ttmp);
else
qtype = fi(0,quotype);
end
end
So, if a specific numeric type is provided in the dialog, I see I get a Simulink.NumericType object and life is good. If one of the other rules is selected, I get a string. As you can see, I can access stuff like the block port handles, but they’re doubles not objects so I have no idea what to do next. I can’t run this in the debugger apparently so I’m limited to my disp() statements that put stuff in the Diagnostic Viewer. The qtype is passed as a parameter into the underlying MATLAB function and the numeric type can be re-fetched by the call fixed.extractNumericType().
Help! After some discussion and playing around, I got some ways in defining a block mask that sets the Simulink (fixed point) data type of an output. i have a mask parameter called "quotype" that is a Data Type parameter, and I can pass a related parameter into my MATLAB Function block that has that data type which can then be acted upon. However, I’d like to support rules such as "Inherit: Inherit via internal rule" and "Inherit: Inherit via back propagation". To do so, I need to be able to retrieve information on the signals/ports as they’re compiling in Mask call back function. To wit: I have the current code that for instance works correctly when a specific data type is invoked:
% Initialization code section
function initialization()
if ~isa(quotype,’Simulink.NumericType’)
ports = get_param(gcb,"PortHandles");
out1 = ports.Outport(1);
in1 = ports.Inport(1);
in2 = ports.Inport(2);
disp(ports)
switch quotype
case ‘Inherit: Inherit via internal rule’
ttmp = fixdt(0,10,2);
case ‘Inherit: Inherit via back propagation’
ttmp = fixdt(0,10,2);
case ‘Inherit: Same as first input’
ttmp = fixdt(0,10,2);
otherwise
disp(quotype)
ttmp = fixdt(0,10,2);
end
qtype = fi(0,ttmp);
else
qtype = fi(0,quotype);
end
end
So, if a specific numeric type is provided in the dialog, I see I get a Simulink.NumericType object and life is good. If one of the other rules is selected, I get a string. As you can see, I can access stuff like the block port handles, but they’re doubles not objects so I have no idea what to do next. I can’t run this in the debugger apparently so I’m limited to my disp() statements that put stuff in the Diagnostic Viewer. The qtype is passed as a parameter into the underlying MATLAB function and the numeric type can be re-fetched by the call fixed.extractNumericType().
Help! mask parameters, port signals MATLAB Answers — New Questions