Persistent variables not working? (Simulink)

10 vues (au cours des 30 derniers jours)
Mike Vukovich
Mike Vukovich le 17 Déc 2014
Commenté : Jared Mach le 22 Fév 2018
I'm trying to implement the following simple test function in Simulink:
function [y, newx] = fcn(xI, T)
%This is a very simple function meant for learning how to properly
%implement "pseudo-feedback" in Simulink.
%xI is merely the initial value of x.
%#codegen
mlock
persistent currentX;
double x;
if isempty(currentX)
x = xI;
else
x = currentX;
end
for t = 1:T
if t > 1
newx = x;
end
y = 1/x;
newx = x+1;
end
end
However, when I try running the model (with a constant input and displays connected to the output), I get the following error message:
Undefined function or variable 'currentX'. The first assignment to a local variable determines its class.
Could anyone help identify the problem?
  1 commentaire
Jared Mach
Jared Mach le 22 Fév 2018
Remove the semicolon at the end of "persistent currentX;"

Connectez-vous pour commenter.

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 17 Déc 2014
currentX is not defined in your code

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by