Info

This question is closed. Reopen it to edit or answer.

Variable updates for a brief moment before returning to the original value.

1 view (last 30 days)
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 Comments
Adam
Adam on 10 Oct 2019
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?
David Eissner
David Eissner on 16 Oct 2019
Because I can place a breakpoint at the line "self.P_avail = P_avail;"
At this point, I can see that P_avail has the correct values. When I execute the line "self.P_avail = P_avail;", I can see my object in the Variable window update and then revert back.

Answers (3)

Steven Lord
Steven Lord on 8 Oct 2019
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.
  2 Comments
David Eissner
David Eissner on 8 Oct 2019
It returns a list of values.
As to your second question, the second. The self object I'm referring to is the one within the Aircraft Class.

Martin C.
Martin C. on 8 Oct 2019
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?

David Eissner
David Eissner on 10 Oct 2019
Anyone have any other thoughts?
I am at a loss why Matlab would change a variable that I have assinged specifically and then revert back to the old values without having stepped forward any farther in the code. That seems impossible in a sense.

Community Treasure Hunt

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

Start Hunting!