我想在Matlab中編寫一個函數並重復調用它。 這是我的代碼:如何在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()
末
我想顯示「Hello」爲知曉它如何運行。這是輸出:
Hello
T =
-135.9965
>>
所以,我的代碼只運行一次而不是重複10次,我該怎麼辦?
看起來你需要一個分號後顯示('你好') –
@JeremyKahan不,我運行這個代碼沒有函數&它顯示'你好',10倍 –
如果你刪除disp('你好')你仍然得到一個溫度? –