フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to define a variable which is numerical and changes in every cycle of the while loop?

1 回表示 (過去 30 日間)
Zarak kh
Zarak kh 2019 年 9 月 26 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello.
I have a code that in a part of it there is a while loop, which is shown as below:
while all(DIST((1:ncities),(1:ncities))<realmax)
[mindist,nextcity]= min(newDIST(currentcity,:))
while [xi yi]>0 & [xi yi]== all(nextcity*(1:2))==0
[xi,yi,ii]=polyxpoly(outxd,outyd,all([currentcity;nextcity],1),all([currentcity;nextcity],2));
[row, col]=find(all(:,1)==transpose(z(ii(:,1),1)));
vec=[row,row+1];
[mindistedge,nextcity]=min(newDIST(vec,currentcity));
nextcity=vec(nextcity);
end
traveleddist=traveleddist+DIST(currentcity,nextcity)
end
I defined all the matrix in the first part when I run the code I got an error "xi" in not defined,so here is my question how can I define xi and yi which changes in each cycle of the loop and I need the loop to run untile there is no intersection between lines.
Thanks for your help in advance.

回答 (1 件)

Rik
Rik 2019 年 9 月 26 日

You should not have an array input to an if or while. Your second conditional could do with some edits.

To solve your actual problem, you will have to assign a value to the variables that make sure you enter the loop.

この質問は閉じられています。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by