while循环中if指令下的加法。
Show older comments
我想用一个坐标作为输入,利用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,请问是哪里出错了?
Accepted Answer
More Answers (0)
Categories
Find more on 数据导入和分析 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!