Info
此问题已关闭。 请重新打开它进行编辑或回答。
Variable updates for a brief moment before returning to the original value.
2 次查看(过去 30 天)
显示 更早的评论
classdef AircraftClass < ModelClass
.
.
.
properties(SetAccess = private)
P_req % Power Required
P_avail % Power Available
end
.
.
.
function obj = AircraftClass(B, C, D, E, R, P, T, Z)
% Class constructor
obj.info
obj.A
obj.B = B;
obj.C = C;
obj.D = D;
obj.E = E;
obj.R = R;
obj.P = P;
obj.T = T;
obj.Z = Z;
obj.B = B.A;
end
.
.
.
function [P_avail, P_req, FuelF_req] = calc_point(self, xmsnLimitFlag)
if nargin==1; xmsnLimitFlag=1; end
P_avail = self.get_PowerAvailable(xmsnLimitFlag);
self.P_avail = P_avail;
[P_req, FuelF_req] = self.get_FuelFlow_PowerRequired();
end
I'm having issues with the "self.P_avail = P_avail" line.
Basically in short, P_avail = self.get_PowerAvailable(xmsnLimitiFlag) updates a list of power data.
However, when I go to assign this new data to self.P_avail, the data updates for a second or two and then reverts back to the old data.
Why is this occuring and how can I make the update permanent?
3 个评论
Adam
2019-10-10
At what point in the code are you looking at the value of self.P_avail? How do you know it updates for a second or two?
回答(3 个)
Steven Lord
2019-10-8
Does the get_PowerAvailable method of this class return a number, an instance of this class, or something else?
When you say "reverts back to the old data" are you looking at the self object inside the calc_point method or are you looking at the object in the workspace that you passed into the calc_point method? If the latter, I'm guessing ModelClass is not a handle class and you don't return the object from the method, so the changes are made only to the copy of the object in the method workspace.
If you want the modified object to be available outside the method, you need to either return it from the method or make your class a handle class. See this documentation page for a discussion of the difference between handle and value classes.
Martin C.
2019-10-8
hmm you might want to use '< handle' if you want to make changes to an object within a method.
Not sure this is your issue.
Could you provide your whole class to better understand what might be going on?
1 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!