欢迎光临散文网 会员登陆 & 注册

实现边界控制的函数 via Matlab语言

2022-12-11 20:09 作者:__牛油果__  | 我要投稿

%% 实现边界控制的函数 via Matlab语言

Lb = [0 0 0 0];

Ub = [8 7 6 5];

s = [10 3 4 9];


%%方法一 apply bounds

s = max(Lb,s);

s = min(Ub,s);


%%方法二 apply bounds

temp=s;

I=temp<Lb;                % I=1×4 logical

temp(I) = Lb(I);

J = temp > Ub;           % J=1×4 logical

temp(J) = Ub(J);

% Update this new move

s = temp;


%%方法三 apply bounds

A=Bounds( s, Lb, Ub)

function s = Bounds( s, Lb, Ub )

 % Apply the lower bound vector

 temp = s;

 I = temp < Lb;            % I=1×4 logical

 temp(I) = Lb(I);

  % Apply the upper bound vector

 J = temp > Ub;           % J=1×4 logical

 temp(J) = Ub(J);

 % Update this new move

 s = temp;

end




实现边界控制的函数 via Matlab语言的评论 (共 条)

分享到微博请遵守国家法律