I want to implement a simple FIFO buffer in the simulink embedded matlab block with width determined by the input from simulink. The outputs should be both the entire contents as a matrix, and the last element. The code below works with option B (see comments), but not with option A. Option A is the desired option, but in this case, simulink reports the following error:
Data 'pres' (#162) is inferred as a variable size matrix, while its specified type is something else.
Can anyone explain how to get this to work? Apparently, setting the problem output to be variable width will fix Option A, but the width does not change during simulation and using variable width causes endless problems down stream.
Thanks in advance, -Jason
function [pvects,pres] = FFstorage(u,Nff) %#codegen
persistent xstore Nu if isempty(xstore) Nu=length(u); xstore = repmat(u,1,Nff); end; %try an initialization pres=zeros(Nu,1);