while循环中if指令下的加法?
7 views (last 30 days)
Show older comments
腾龙娱乐电话17787482287
on 18 Apr 2022
Answered: starlight Smith
on 18 Apr 2022
我想用一个坐标作为输入,利用while循环与一组三维变量做对比,其中第一列作为x轴,第二列作为y轴,测定输入坐标与变量坐标之间的距离,若小于10,则提取变量第三列数据累加,代码如下:
load('matlab.mat')
A=[1,2];
B=Untitled;
C=Untitled1;
n=size(B,1);
e=0;
i=1;
while i < n+1
a=B(i,:);
b=a(:,1:2);
c=a(:,3);
d=norm(A-b);
if d<10
e=e+c;
i=i+1;
else
i=i+1;
end
end
但是最后i的值一直在加,可e的值一直都是0,请问是哪里出错了?
0 Comments
Accepted Answer
starlight Smith
on 18 Apr 2022
如果你这个 d=norm(A-b) 对于全部的 b 值,始终保持 d>=10 ,那含有 e=e+c; 的分支永远进不去,自然只有 i 在增加了
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!