Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2013-04-07
帖子: 5
声望力: 0 ![]() |
![]()
已知数据如下
qidian=4; zhongdian=3; course = 1 2 0 4 1 0 0 0 1 0 been = 2 1 2 3 NaN NaN 1 4 5 1 NaN NaN NaN NaN NaN NaN 1 6 NaN NaN 我的程序代码如下 temppoint=zhongdian; while 2 [m n]=find(been==temppoint); tem=m; for i2=tem; if course(i2)~=0&course(i2)~=temppoint xxx=been(i2,: ); newpoint=xxx(xxx~=temppoint); st=[st newpoint]; break; end end if newpoint==qidian break; end temppoint=newpoint; end 运行的时候是死循环,我检查了很多遍都没看出错误在哪里,求大神帮助!谢了 PS:我这个循环是用来从zhongdian出发,逐个搜索been,看他对应的course是否(既不等于0,也不等于temppoint),直到qidian |
![]() |
![]() |
![]() |
#2 |
初级会员
注册日期: 2013-04-07
帖子: 5
声望力: 0 ![]() |
![]()
哎,还是自己找到原因的,都没人回答。
我来说下吧, 因为tem返回的是列向量 我的while中直接用了一个for i2=tem 这是不对的 并不能让i2依次取到tem中的每个数 i2只能取到tem中的第一个数值 但是如果将tem转换为行向量 就可以了 |
![]() |
![]() |