Insert Zeros into Random Number Stream
The cm_insert_zeros
model uses MATLAB® code and a MATLAB Function
block to insert zeros into a random number stream.
The MATLAB Function
block, labeled Insert Zero
in this model, executes this code to insert zeros in the random number stream input to it.
MATLAB Code Run by Insert Zero
function y = fcn(u,insertZeroVector) numSeg = length(u)/sum(insertZeroVector); c = zeros(length(insertZeroVector), numSeg,'like',u); c(logical(insertZeroVector),:) = reshape(u,[],numSeg); y = c(:); end
The length of the input must be an integer multiple of the number of 1s in the Insert zero vector parameter
. The block repeats the Insert zero vector, when necessary, to output all input elements. For this example, the Insert zero vector
parameter is set to [1 1 0 1 0 1]'.