Convert variable-sized signal to fixed

16 visualizzazioni (ultimi 30 giorni)
John F
John F il 6 Apr 2022
Risposto: Shlok il 21 Ott 2024
I have a custom block (block on the right) that takes a fixed size signal, but I would like to adjust the size of the input signal as needed. The subsystem that is present 10 times in the photo below outputs a number if it's input is 1 or an empty signal if it is zero. Then I make the 10 signals into 1 using a bus selector. However, the output signal of the bus selector is of variable-size. Is there any way to convert a variable sized signal to fixed?

Risposte (1)

Shlok
Shlok il 21 Ott 2024
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:

Categorie

Scopri di più su Interactive Model Editing in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by