How to keep a constant value of a variable during the execution of the code in Matlab

2 次查看(过去 30 天)
Hello everyone, I have a short (and I reckon silly as well) question about manipulation of variables in Matlab codes. How can I keep a constant value of a variable (assigned during the execution of the code), while the code executes further? So basically put the value into the memory and don't change it all. As an example of the code on which I am working right now:
if SystemTriggered ==1;
if Accelerationflag == 1;
for n = 1:1:100
AOrder = 1/2*HMSpeed^2/(Acc+n*2*pi);
if AOrder<Alim;
k = n;
Accelerationflag = 0;
break;
end
end
end
Offset = k;
AccOffset = PhaseIni - Offset*2*pi;
%Derivation conditions
if My condition here;
HmSpeedReached = 1;
end
end
So I am looking for an option, how I can keep the calculated value of "Offset" when I got "HmSpeedReached =1". Since we have a "for" cycle in the beginning (that will assign a value to K and then to Offset), so I just need to keep that number as a value of the variable all the time, after the condition of HmSpeedReached is satisfied... Thank you in advance.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by