完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
|
总是在[~,b2(i)] 这种破折号上停下来 说 Expression or statement is incorrect--possibly unbalanced (, {, or [. 到底为啥呢
代码是教材COPY的, 不应该错啊 function [PIPxy]=PIPs(ys,nofPIPs,typeofdist,pflag) l=length(ys); xs=(1:l)';% Column vector with xs PIP_points=zeros(l,1);% Binary indexation PIP_points([1,l],1)=1;% One indicate the PIP points.The first two PIPs are the first and the last observation. Adjacents=zeros(l,2); currentstate=2;% Initial PIPs while currentstate<=nofPIPs Existed_Pips=find(PIP_points); currentstate=length(Existed_Pips); locator=nan(l,currentstate); for j=1:currentstate locator(:,j)=abs(xs-Existed_Pips(j,1)); end b1=zeros(1,l);b2=b1; for i=1:l [~,b1(i)]=min(locator(i,:));% Closer point locator(i,b1(i))=nan; % Do not consider Closer point [~,b2(i)]=min(locator(i,:));% 2nd Closer Point Adjacents(i,1)=Existed_Pips(b1(i));%x-coordinates of the closer point Adjacents(i,2)=Existed_Pips(b2(i));%x-coordinates of the 2nd closer points end %% Calculate Distance Adjx=Adjacents; Adjy=[ys(Adjacents(:,1)),ys(Adjacents(:,2))]; Adjx(Existed_Pips,:)=nan;% Existed PIPs are not candidates for new PIP. Adjy(Existed_Pips,:)=nan; if typeofdist==1 [D]=EDist(ys,xs,Adjx,Adjy); elseif typeofdist==2 [D]=PDist(ys,xs,Adjx,Adjy); else [D]=VDist(ys,xs,Adjx,Adjy); end [~,Dmax]=max(D); PIP_points(Dmax,1)=1; currentstate=currentstate+1; end PIPxy=[Existed_Pips, ys(Existed_Pips)]; %% Plot if pflag==1 plot(ys), hold on plot(Existed_Pips,ys(Existed_Pips),'r*'),hold off end end %% Distance measures % Euclidean Distance function [ED]=EDist(ys,xs,Adjx,Adjy) ED=((Adjx(:,2)-xs).^2+(Adjy(:,2)-ys).^2).^(1/2)+. . . ((Adjx(:,1)-xs).^2+(Adjy(:,1)-ys).^2).^(1/2); end % Perpendicular Distance function [PD]=PDist(ys,xs,Adjx,Adjy) slopes=(Adjy(:,2)-Adjy(:,1))./(Adjx(:,2)-Adjx(:,1)); constants=Adjy(:,2)-slopes.*Adjx(:,2); PD=abs(slopes.*xs-ys+constants)./(slopes.^2+1).^(1/2); % line function: y=kx+m (1) % the perpendicular distance (PD) from a point p(x1,y1) to a line % is given by the following formula: % PD=abs(k*x1-y1+m)/sqrt(k^2+1) end % Vertical Distance function [VD]=VDist(ys,xs,Adjx,Adjy) slopes=(Adjy(:,2)-Adjy(:,1))./(Adjx(:,2)-Adjx(:,1)); constants=Adjy(:,2)-slopes.*Adjx(:,2); Yshat=slopes.*xs+constants; VD=abs(Yshat-ys); end |
|
相关推荐
2个回答
|
|
|
重新检查下程序吧
|
|
|
|
|
|
就是卡在 ~ 破折线 程序应该没问题,我直接COPY的。
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
我用matlab的coder 封装了一个c语言的dll, 但是在用labview调用时,会出现识别不到库的问题,有大神遇到过吗
2673 浏览 0 评论
5246 浏览 0 评论
在matlab中如何计算含有第一类修正的贝塞尔函数的积分算不出的问题?
9043 浏览 0 评论
怎么利用matlab得到95%,80%和70%的置信区间,并生成不同区间下的功率误差贝塔分布?
10485 浏览 0 评论
请问simulink的s-function模块如何添加多输入输出接口
14660 浏览 2 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 21:52 , Processed in 0.534751 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
3525