Problem with my function
1 回表示 (過去 30 日間)
古いコメントを表示
I have a fitness function as shown below.
function z=sample_fit(r)
Flag=0;
while ~Flag
//take inputs from user
Flag=1;
end
//process the inputs
The above function is called for n times by a GA solver. The problem is that, use of flag in the function is useless as it is always set to zero on every iteration. I want the user to be requested for input only once in the first iteration and for rest of the iterations it will use the values provided in the first iteration.
0 件のコメント
回答 (1 件)
per isakson
2014 年 7 月 9 日
If in the first iteration the word, iteration, means call of the function, sample_fit, see persistent, Define persistent variable
2 件のコメント
per isakson
2014 年 7 月 9 日
If you make a simple example to try this construct you will find that it doesn't work. Flag=0 (btw: I prefer Flag=false) will be executed every time; nothing achieved with persitent.
See first example in documentation of persistent. You need something like
if isempty( Flag )
Flag = false;
end
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!