Effacer les filtres
Effacer les filtres

Building a memory with m-file

1 vue (au cours des 30 derniers jours)
Ion
Ion le 10 Déc 2013
Commenté : Ion le 10 Déc 2013
Hello,
I have a little problem with my model when I try to create an intelligent memory to my application. The model is shown below:
The Matlab-function block called "Memory Backup" gets data packets into its port "last_data". The data is delayed with one data step, but don´t worry about it. How the Matlab function should work, is told below:
If there are packet losses (boolean 1 (=losses) or 0 (=no losses)), the Memory backup function starts to feed out the last correct data (last last_data -signal during "no losses" time) that was occured before the losses started to appear.
When the packet losses disappear (packet_loss = 0), then the Memory backup -function just feeds through the input data (last_data -signal).
What is inside the Memory backup file, is shown below:
In order to get the Memory backup- function to work, I should find a way where to declare the variable "keep_old_output". I can´t assign it to a 0 or 1 at the beginning of the script because it would affect to the functionality of the script everytime when the script would be run.
Where should I declare it without disturbing the functionality of the script?
Thank you for any kind of help!

Réponse acceptée

Rajiv Ghosh-Roy
Rajiv Ghosh-Roy le 10 Déc 2013
You need to declare these variables as "persistent". You can check isempty of these variables for initialization.
function y = fcn(packet_loss, last_data)
persistent keep_old_data
persistent another_persistent
% Initialize
if isempty(keep_old_data)
keep_old_data = false;
another_persistent = uint32(23);
end
end
  1 commentaire
Ion
Ion le 10 Déc 2013
Thank you!
Indeed the keyword here was the 'persistent' that solved the problem.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programmatic Model Editing 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!

Translated by