How to write a specific number via a loop
이전 댓글 표시
I have a code that
1)reads two files
2)calculates distances between points of file1 and point of file 2
3) writes an output with the distnces less than 2km.
The problem is that I would like to add to the output file one extra column that concludes specific number of each row
my code is
data=readcell('file1.txt')
lat1=cell2mat(data(4:end,2))
lon1=cell2mat(data(4:end,3))
value=cell2mat(data(4:end,5))
filename1= 'file2.txt' %arxeio me makroseismika
[d1,tex]= importdata(filename1);
lat2=d1.data(:,2);
lon2=d1.data(:,1);
c=d1.data(:,4);
for z=1:numel(stname)
distances = (deg2km(distance(lat1(z),lon1(z),lat2,lon2)));% Compute distances
withinkm = distances <= 2; % Find row indexes where the distance is less than 2 km.
% Extract only those close points from the set of all points.
closePointskm = [lat2(withinkm), lon2(withinkm), c(withinkm), distances(withinkm), value(z:numel(withinkm))]
writematrix()
end
The problem is in the line 23.
command window shows me:
Could you please help me?
채택된 답변
추가 답변 (1개)
Oliveira Pereira
2021년 9월 10일
0 개 추천
I worked on the old principle
Getting the sum using a for loop implies that you should:
Create an array of numbers, in the example int values.
Create a for statement, with an int variable from 0 up to the length of the array, incremented by one each time in the loop.
In the for statement add each of the array's elements to an int sum.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


