Hi John,
I understand you're looking for an approach to convert a variable-sized signal into a fixed size. You can achieve this by using a “MATLAB Function” block. This block allows you to write custom MATLAB code within Simulink to perform calculations, control logic, or manipulate signals.
Within this function block, you can reshape the incoming signal, either by padding it with zeros or removing excess values to match the desired fixed size. This method allows you to manage the signal's dimensions dynamically and keeps a consistent output size for further processing in your Simulink model.
Here’s a sample code of the function:
% u: input signal (1-D Array)
% fixedSize: size of output signal (Integer)
function y = varToFixedSize(u, fixedSize)
y = zeros(fixedSize, 1);
inputSize = length(u); % Determine the size of the input signal
if inputSize <= fixedSize
y(1:inputSize) = u;
else
y = u(1:fixedSize);
end
end
To know more about “MATLAB Function” block, you can refer to the following MATLAB documentation: