完善资料让更多小伙伴认识你,还能领取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的。
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
使用simulink进行三相短路故障分析时,各参数应该如何设置
1294 浏览 1 评论
想请教一下图中是simulink的什么模块,需要这种三段斜率函数模块但没找到在哪
1419 浏览 1 评论
2334 浏览 1 评论
200圆!求助大佬给一份VSG并网和离网模式的simulink仿真
2600 浏览 0 评论
MATLAB(3)--矩阵的引用(sub2ind、ind2sub、reshape函数使用)
3431 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 07:44 , Processed in 0.587042 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号