Persistent variables not working? (Simulink)

조회 수: 10 (최근 30일)
Mike Vukovich
Mike Vukovich 2014년 12월 17일
댓글: Jared Mach 2018년 2월 22일
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
Jared Mach
Jared Mach 2018년 2월 22일
Remove the semicolon at the end of "persistent currentX;"

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 17일
currentX is not defined in your code

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by