私は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
T =
-135.9965
>>
私のコードは10回繰り返す代わりに1回だけ実行されます。どうすればいいですか?
disp( 'Hello')の後にセミコロンが必要なように見える –
@JeremyKahanいいえ、このコードを機能なしで実行し、 'Hello'、10回表示 –
disp( 'Hello')を削除すると、ちょっと温度が上がる? –