How to write a specific number via a loop
Show older comments
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?
Accepted Answer
More Answers (1)
Oliveira Pereira
on 10 Sep 2021
0 votes
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.
Categories
Find more on Matrix Indexing 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!

