simple buffer in simlink embedded matlab
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, all-
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
CODE:
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);
xstore(1:Nu,1:Nff-1)=xstore(1:Nu,2:Nff);
xstore(1:Nu,Nff)=u;
pvects=xstore;
%Option A: this is the desired output
pres=xstore(1:Nu,1);
%Option B: this works, but it is not the desired output
% % pres=u;
0 commentaires
Réponses (1)
Ryan G
le 14 Déc 2012
What is the size of pres on line ~11 versus the size on line ~18? It looks like the size of the output of
xstore(1:Nu,1)
may be different from
zeros(Nu,1)
Does pres need to be initialized in this code? It's hard to tell at first glance.
0 commentaires
Voir également
Catégories
En savoir plus sur Sources dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!