我想在Matlab中编写一个函数并重复调用它。 这是我的代码:
function T=FirstTemperature()
clc
T=0.8;
randVariable=10*rand(1,2);
ErandVariable=Objectivef(randVariable(1),randVariable(2));
present=randVariable;
Epresent=ErandVariable;
DEpositive=0;
positive=0;%for counting DeltaEpositive
for i=1:10
randVariable=10*rand(1,2);
ErandVariable =Objectivef(randVariable(1),randVariable(2));
DE=(ErandVariable-Epresent);
if(DE<0)
present=randVariable;
Epresent=ErandVariable;
% disp('i move there')
else
DEpositive=DE+DEpositive;
positive=positive+1;%for counting
P=exp(- (DE)/ (2.038*T));
a=rand(1);
if(P>a)
present=randVariable;
Epresent=ErandVariable;
%disp('with A probability i accepted')
end
end
end
x0=0.9;
averag=DEpositive/positive;%average of deltapositive
T=averag/log(x0);
end
我在脚本文件中重复调用此函数,这样:
for k=1:10
disp('Hello')
T=FirstTemperature()
端
我想要显示&#34;你好&#34;了解它是如何运行的。这是输出:
Hello
T =
-135.9965
>>
所以,我的代码只运行一次而不是重复10次,我该怎么办?