Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Variable updates for a brief moment before returning to the original value.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Adam
il 10 Ott 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?
Risposte (3)
Steven Lord
il 8 Ott 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.
Martin C.
il 8 Ott 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?
1 Commento
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!