Persistent Variable will not update in a function call

조회 수: 12 (최근 30일)
Alyssa
Alyssa 2015년 5월 6일
댓글: Stephen23 2015년 5월 12일
I have a sub-function of an EML Simulink Block that has a persistent variable, wm_last, declared. The variable is not used anywhere other than within this function call. I keep getting an error when I try to update this variable. When he line, "wm_last = wm" is uncommented, my model will not build. What gives?
function corr = LeverArmCorrection(m_deltaTime, deltaThetaMountingFrame, ...
earthRateMountingFrame)
persistent wm_last
if isempty(wm_last)
wm_last = zeros(1,3);
end
m_TableLeverArm = [0.00524; 0.4416; 1.2755];
%mounting to ENA frame rate (rad/sec)
wm = (deltaThetaMountingFrame / m_deltaTime) - earthRateMountingFrame;
%mounting to ENA frame angular acceleration (rad/sec^2)
am = (wm - wm_last) ./ m_deltaTime;
% wm_last = wm;
%mounting frame sensed acceleration sensitivity to lever arm
XM = zeros(3,3); % mounting frame sensed accel sensitivity to lever arm (ft/sec^2/ft)
XM(1, 1) = -wm(2).^2 - wm(3).^2;
XM(2, 2) = -wm(1).^2 - wm(3).^2;
XM(3, 3) = -wm(1).^2 - wm(2).^2;
XM(1, 2) = wm(1) * wm(2) - am(3);
XM(1, 3) = wm(1) * wm(3) + am(2);
XM(2, 1) = wm(2) * wm(1) + am(3);
XM(2, 3) = wm(2) * wm(3) - am(1);
XM(3, 1) = wm(3) * wm(1) - am(2);
XM(3, 2) = wm(3) * wm(2) + am(1);
%lever arm correction (ft/sec^2)
XRM = (XM * m_TableLeverArm)';
corr = XRM .* m_deltaTime;
end
  댓글 수: 2
Sebastian Castro
Sebastian Castro 2015년 5월 8일
What's the error you're getting?
Alyssa
Alyssa 2015년 5월 11일
I get an "Error occured during pasring of Matlab Funciton 'GCA/Local/..."
If I comment out the "wm_last = wm" as shown above, the model compiles and runs just fine. Error doesn't give you much, does it...

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

답변 (1개)

Image Analyst
Image Analyst 2015년 5월 8일
Try making it global instead of persistent. It should work then.
  댓글 수: 4
Alyssa
Alyssa 2015년 5월 11일
When I make the variable global, I get a port dimension error. I'm completely stumped. We have persistent variables in multiple other subfunctions - updated in exactly the same way. This makes no sense.
Stephen23
Stephen23 2015년 5월 12일
@Alyssa: can you please give us the complete error message, which includes all of the red text.

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

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by