声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1051|回复: 2

[编程技巧] 这个条件判断是多余的吗?

[复制链接]
发表于 2007-5-5 03:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
while SD > 0.3
% 找极值点

d = diff(h);
% approximate derivative

maxmin = [];


for i=1:N-2

if d(i)==0
% we are on a zero

maxmin = [maxmin, i];

elseif sign(d(i))~=sign(d(i+1))


% we are straddling a zero so

maxmin = [maxmin, i+1];
% define zero as at i+1 (not i)

end

end



if size(maxmin,2) < 2
% 极值点数目小于2个跳出循环

break
%(maxmin,2)中的2代表列数即极值点数

end



% divide maxmin into maxes and mins

if maxmin(1)>maxmin(2)
% first one is a max not a min

maxes = maxmin(1:2:length(maxmin));

mins
= maxmin(2:2:length(maxmin));

else

% is the other way around

maxes = maxmin(2:2:length(maxmin));

mins
= maxmin(1:2:length(maxmin));

end



% 极值点的位置信息

maxes = [1 maxes N];

mins
= [1 mins
N];


这个程序,其中请主要关注这两个地方
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:N-2

if d(i)==0
% we are on a zero

maxmin = [maxmin, i];

elseif sign(d(i))~=sign(d(i+1))


% we are straddling a zero so

maxmin = [maxmin, i+1];
% define zero as at i+1 (not i)

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if maxmin(1)>maxmin(2)
% first one is a max not a min

maxes = maxmin(1:2:length(maxmin));

mins
= maxmin(2:2:length(maxmin));

else

% is the other way around

maxes = maxmin(2:2:length(maxmin));

mins
= maxmin(1:2:length(maxmin));

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
请问这个判断maxmin(1)>maxmin(2) 是不是多余的?

[ 本帖最后由 eight 于 2007-5-5 11:21 编辑 ]
回复
分享到:

使用道具 举报

 楼主| 发表于 2007-5-5 12:16 | 显示全部楼层
这个判断maxmin(1)>maxmin(2)条件是不是恒为真?下面的程序每次都执行
maxes = maxmin(1:2:length(maxmin));
mins
= maxmin(2:2:length(maxmin));
这两句,但对求包络结果没有影响,因此可以简化只有这两句
maxes = maxmin(1:2:length(maxmin));
mins
= maxmin(2:2:length(maxmin));
不知我这样分析对不对?
 楼主| 发表于 2007-5-5 14:49 | 显示全部楼层
怎么没有人看一下呢?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-12 12:48 , Processed in 0.053457 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表