[英]How add condition statement in an array? - MATLAB
I'm working on a mapping by linking 2 coordinates together and my database is huge. 我正在通过将2个坐标链接在一起来进行映射,而我的数据库很大。 Hence I only display part of the work on what I had done. 因此,我只展示我所做的部分工作。
Question: I would like to add the start and stop number together. 问题:我想将开始和结束号码加在一起。 If it is more than 1,000,000 the distance will be 100. Else the distance will remain unchanged. 如果大于1,000,000,则距离将为100。否则,距离将保持不变。 Then I would like it to store it in a single array. 然后,我希望将其存储在单个数组中。
Really appreciate your respond. 非常感谢您的回应。 Thanks :) 谢谢 :)
Coding 编码
clear;
N = xlsread('RegionAll.xlsx',2);
M = xlsread('RegionAll.xlsx',1); % List of Coordinates
distance = distance(M(start,3:4), M(to,3:4)); % Coordinates
distancekm = deg2km(distance);
sum = N(:,1)+N(:,2);
%Problem a below
for l = 1:625
sum = N(l,1)+N(l,2);
if (sum>1000000)
a = 100;
else
a = distancekm(l,1);
end;
end
Excel Data Sample in variable N 变量N中的Excel数据示例
Start Stop Distance
13054 13055 0.017749628
13055 13001 0.152363674
560601 13043 0.063200318
560601 13042 0.036090789
560601 13041 0.021083981
560601 13037 0.04975146
560604 13031 0.047614849
560604 13030 0.051513765
560604 13029 0.076687991
560604 560605 0.060676069
560605 560606 0.046497332
First sum columns 1 & 2, store the result in SumMatrix
: 第一和列1和2将结果存储在SumMatrix
:
SumMatrix = N(:,1) + N(:,2);
Then replace all values > 1000000
in SumMatrix
with 100
by using logical addressing: 然后,使用逻辑寻址将SumMatrix
所有> 1000000
值替换为100
:
SumMatrix(SumMatrix > 1000000) = 100;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.